Fixed enemy death resuming spawner timers unexpectedly. Now checks if the constant spawn is done to decide if spawning should end.

This commit is contained in:
Ader Alisma 01 2024-02-04 18:25:23 -05:00
parent 9188e86adb
commit 0fd0584a50
5 changed files with 82 additions and 13 deletions

View File

@ -0,0 +1,23 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: eb0795e326609f0499365f5b65c2b5cd, type: 3}
m_Name: WaveConfig_Test
m_EditorClassIdentifier:
_constantSpawn:
- _enemy: {fileID: 80204295746100150, guid: 1be769d6ef642314b8846bed35e7297c, type: 3}
_count: 20
_nestedGroupSpawn:
- groupSpawn:
- _enemy: {fileID: 80204295746100150, guid: 5bbf0d85fa5bb3f4599da79f0a84e3a9, type: 3}
_count: 2
triggerTime: 2
_gameDuration: 3

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 61b21509b3e4be0438ea87b4e7a73e17
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -87,16 +87,31 @@ public class WaveObserver : Singleton<WaveObserver>
if (_levelConfig.ConstantSpawn[i].GetEnemyObject() == paramPrefab) if (_levelConfig.ConstantSpawn[i].GetEnemyObject() == paramPrefab)
{ {
currentCount = --_copyConstantSpawn[i]; currentCount = --_copyConstantSpawn[i];
break; //break;
} Debug.Log("Amout to spawn is now: " + currentCount);
}
if (currentCount <= 0) if (currentCount <= 0)
{
bool hasNextTarget = false;
for (int j = i; j < _copyConstantSpawn.Count; j++)
{
if (_copyConstantSpawn[_copyConstantSpawn.Count - j] > 0)
{
spawnerSubject.Prefab = _levelConfig.ConstantSpawn[j].GetEnemyObject();
hasNextTarget = true;
Debug.Log(spawnerSubject.Prefab.name);
}
}
if (!hasNextTarget)
{ {
foreach (SpawnerTile spawner in _subjects) foreach (SpawnerTile spawner in _subjects)
{ {
if (spawner.Prefab.Equals(paramPrefab)) if (spawner.Prefab.Equals(paramPrefab))
{ {
spawner.StopSpawn(); spawner.StopSpawn();
Debug.Log("----Spawn Stopped----");
}
}
}
} }
} }
} }
@ -122,12 +137,34 @@ public class WaveObserver : Singleton<WaveObserver>
* Called when an enemy dies * Called when an enemy dies
* Reactivates spawning on that row if disabled before * Reactivates spawning on that row if disabled before
*/ */
public void NotifyDies(int position, float toughness) public void NotifyDies(int position, float toughness, GameObject paramPrefab)
{ {
_aliveEnemyCount[position] -= toughness; _aliveEnemyCount[position] -= toughness;
if (_aliveEnemyCount[position] < MAXTOUGHNESS) if (_aliveEnemyCount[position] < MAXTOUGHNESS)
{
for (int i = 0; i < _copyConstantSpawn.Count; i++)
{
if (_levelConfig.ConstantSpawn[i].GetEnemyObject() == paramPrefab)
{
// Checks if there are more of the same type to create
if (_copyConstantSpawn[i] > 0)
{ {
_subjects[position].StartSpawn(); _subjects[position].StartSpawn();
break;
}
for (int j = i; j < _copyConstantSpawn.Count; j++)
{
// Checks if there are other types to create
if (_copyConstantSpawn[_copyConstantSpawn.Count - j] > 0)
{
_subjects[position].Prefab = _levelConfig.ConstantSpawn[j].GetEnemyObject();
_subjects[position].StartSpawn();
break;
}
}
break;
}
}
} }
} }

View File

@ -63,7 +63,7 @@ public class Opponent : Entity
public override void Death() public override void Death()
{ {
_observer.NotifyDies(_observerIndex, _toughness); _observer.NotifyDies(_observerIndex, _toughness, gameObject);
base.Death(); base.Death();
} }

View File

@ -60,8 +60,9 @@ public class SpawnerTile : LevelTile
} }
} }
} }
Debug.Log("Time: " + _spawnCounter);
if (_spawnCounter < _spawnSpeed) return; if (_spawnCounter < _spawnSpeed) return;
Debug.Log("Stopped but still spawning");
_spawnCounter = 0; _spawnCounter = 0;
if (!_cooldownEnded) if (!_cooldownEnded)
{ {