Skip to content

Commit

Permalink
fix spawn related bug on gameover
Browse files Browse the repository at this point in the history
  • Loading branch information
Zamizmi committed Oct 7, 2024
1 parent 7c45708 commit c92221b
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions Assets/_Scripts/Managers/WaveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<AnimalBehaviour>();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c92221b

Please sign in to comment.