How To Make Enemies Spawn In Waves
A common approach to combat in games that is akin to the Arcade Genres of old utilizes a mechanic to spawn sets of enemies into the game at certain points. This is used to create a reprieve between stints of combat, as well give the player a feeling of accomplishment and/or progress.
For this example, I will be using a mixture of loops within coroutines to allow for delayed time intervals with WaitForSeconds().
When called upon, this coroutine checks if the player is alive with the “_stopSpawning” boolean variable. Then it begins spawning one enemy per second until it has spawned as many as indicated by the “_enemiesSpawnCount” integer variable. Once all enemies are spawned the method then exits the for loop and enters the next while loop. This loop is set to check if there are any more enemies alive every .1 of a second. Once all enemies have been killed this loop ends and the primary while loop waits for 2 seconds before starting again.
This whole system could be customized/enhanced with all kinds of additional features. For example, you could switch out the instantiation of a singular enemy with a method that spawns a set, or random set of enemies.