Phase 2 — Wave System

The enemies will spawn in waves, and the game will announce the start of each wave.

To begin, we add a new Text element to the UI Manager that will display the wave via a coroutine, for three seconds.

UI Manager script

The main meat of the wave functions are in the Spawn Manager, which now needs to know about the UI Manager to call that coroutine to display the wave text.

Spawn Manager script

The coroutine also waits for three seconds before spawning enemies. The amount of enemies it spawns is passed in via the int argument, which starts at 3. The Spawn Manager also initializes the variable with the same value.

As the game spawns enemies, is decremented, until it hits zero, stops spawning, and it’s up to the player to clear the map of enemies.

In the Enemy script, each time an enemy dies, it calls the method, which does what it says on the box. When hits zero and there are still waves to spawn, it increments the current wave, increases the amount of enemies to spawn by another 3, and starts another spawning coroutine.

Enemy script