Anyone got a good pointers on creating a legit game wave design? I want to create some kind of delay between each spawn. Ive tried different methods and its not working well. Any ideas?
Make two IEnumerator functions - one which holds the order of the waves and one which actually spawns the waves.
First IEnumerator - the one which controls the order which the waves come in:
IEnumerator StartEnemyWaves()
{
yield return StartCoroutine(GenerateEnemyWave(10,5);// First value is number of enemies to spawn, second value is waiting time.
yield return StartCoroutine(GenerateEnemyWave(20,15);
yield return StartCoroutine(GenerateEnemyWave(30,20);
}
The above code will only move to the next line when the referenced co-routine on its current line finishes. IE it will go through them in order 1 by 1.
Below is the associated spawn enemy function (obviously simplified - I imagine you have more information in your SpawnWave(). You could instead of using the idea of passing the parameters for the wave above pass the correct case for your switch
IEnumerator GenerateEnemyWave(int numberOfEnemies, float lengthOfWave)
{
//Instantiation code for your wave.
yield return new WaitForSeconds(lengthOfWave);
}
You could of course instead of passing the int for numbers of enemies to spawn you could pass the case of the switch statement you want to go down.
IEnumerator StartEnemyWaves()
{
yield return StartCoroutine(GenerateEnemyWave(YourWaveEnum.waveType1,5);// First value is number of enemies to spawn, second value is waiting time.
yield return StartCoroutine(GenerateEnemyWave(YourWaveEnum.waveType2,15);
yield return StartCoroutine(GenerateEnemyWave(YourWaveEnum.waveType2,20);
}
IEnumerator GenerateEnemyWave(YourWaveEnum waveType, float lengthOfWave)
{
switch (YourWaveEnum)
{
case YourWaveEnum.waveType1:
//Wave 1 code
break;
case YourWaveEnum.waveType2:
//Wave 2 code
break;
case YourWaveEnum.waveType3:
//Wave 3 code
break;
}
yield return new WaitForSeconds(lengthOfWave);
}
The asset store has a free thing called “spawner”, it lets you set waves(timed, everybody dead, etc), bosses etc