Hi,
Ok, so I’ve added a couple of Debug.Log
statements so we can see what is happening, I’ve also dialled the 100f delay down to 5f, in the Inspector.
IEnumerator TimeBetweenWaves()
{
Debug.Log("TimeBetweenWaves Starting");
yield return new WaitForSeconds(timeBetweenWaves);
Debug.Log("TimeBetweenWaves Finishing");
}
The code is running as it should, TimeBetweenWaves
gets called, 5 seconds pass, then the second Debug.Log
statement is produced.
What you don’t have in TimeBetweenWaves
though is anything that really does anything, so you call your coroutine and it says ok, I’ll just pop off and do this then. Meanwhile, everything carries on.
If you change the line of code where you call the coroutine from this;
StartCoroutine(TimeBetweenWaves());
to this;
yield return StartCoroutine(TimeBetweenWaves());
You will get the wait effect that you want.
That method would look like this;
private IEnumerator SpawnAllWaves()
{
for (int waveIndex = startingWave; waveIndex < waveConfigs.Count; waveIndex++)
{
var currentWave = waveConfigs[waveIndex];
yield return StartCoroutine(SpawnAllEnemiesInWave(currentWave));
yield return StartCoroutine(TimeBetweenWaves());
}
}
Hope this helps