Phase 2: Waves
Objective: Set up a wave system that includes more enemies as it progresses
Systems like these can be implemented in many ways but I decided to go with this one as a base that can be altered later. To start open the SpawnManger script and set up int variables for baseEnemies, waveLevel, enemiesToSpawn, enemiesRemaining and enemiesSpawned. We also need a link to the UIManger so create a private UIManager and use the GameObject find and get component with a null check in the Start method. We set the baseEnemies to 4 and waveLevel to 1 just as a starting point, then in the Start method set enemiesToSpawn equal to baseEnemies plus the waveLevel and set the remainingEnemies equal to enemiesToSpawn.
We add a UI text element to the canvas for the wave level and create and assign the entry in the UIManager publicly taking in an integer value.
In the SpawnManager create a coroutine for starting each wave which will set the spawning variables like before updated at each new wave. We use this coroutine to start the SpawnEnemies and SpawnPowerup coroutines.
We create a public void EnemyDestroyed method that reduces the remaining enemies or stops spawning, increased the wave level and start the next wave coroutine.
The above method is called from the OnTriggerEnter when an enemy is destroyed by hitting the player, been hit by the players laser or players EMP.
In the next post, we will look at updating the enemy system.