diff --git a/Assets/_Scripts/Managers/WaveManager.cs b/Assets/_Scripts/Managers/WaveManager.cs index 0bfb8c8..fa77121 100644 --- a/Assets/_Scripts/Managers/WaveManager.cs +++ b/Assets/_Scripts/Managers/WaveManager.cs @@ -49,13 +49,23 @@ private void OnStateChangedHandler(object sender, GameLoopManager.OnStateChanged case GameLoopManager.GameStates.GAME_ACTIVE: StartWave(); break; + case GameLoopManager.GameStates.GAME_OVER: + HandleGameOver(); + break; } } + private void HandleGameOver() + { + ResetTimers(); + isSpawning = false; + } + private void PrepareWave(LevelSO newLevel) { ClearAnimals(); - activeIndex = 0; + ResetTimers(); + isSpawning = false; waveContent = new AnimalSO[newLevel.animalsToSpawn.Length]; waveContent = newLevel.animalsToSpawn; OnWavePrepared?.Invoke(this, new OnWaveStartedArgs @@ -64,6 +74,16 @@ private void PrepareWave(LevelSO newLevel) }); } + private void ResetTimers() + { + activeIndex = 0; + spawnTimer = 0f; + OnProgressChanged?.Invoke(this, new IHasProgress.OnProgressChangedEventArgs + { + progressNormalized = spawnTimer / timeBetweenSpawns + }); + } + private void ClearAnimals() { AnimalBehaviour[] animals = FindObjectsOfType(); @@ -122,13 +142,12 @@ private void Update() progressNormalized = 1f }); } - + spawnTimer += Time.deltaTime; if (spawnTimer > timeBetweenSpawns) { SpawnNext(); spawnTimer = 0f; } - spawnTimer += Time.deltaTime; OnProgressChanged?.Invoke(this, new IHasProgress.OnProgressChangedEventArgs { progressNormalized = spawnTimer / timeBetweenSpawns