2D Shooter: The Wave System
Objective: Create a wave system that spawns more enemies each wave.
In our spawn manager script we’ll need to create some variables.
Now for the enemies to increase in number in every wave, we’ll want to add a value to a base number for _enemiesLeft. Let’s just make that value the waveNumber. _maxEnemies will need the same treatment, but we want to keep this variable the same to check it with _enemiesDead later.
If you remember in the last article, we sent a wave number from the asteroid script to the UImanager script. We’ll be sending that same number here.
Now we’ll want to make sure that every time an enemy is instantiated, _enemiesLeft goes down. When it reaches 0, we want _stopSpawning to be true, otherwise we want to keep spawning enemies.
Now we’ll want a new method to determine when an enemy dies. This is so that a new wave won’t start until all the enemies of the current wave are dead. Once no enemies are left to be spawned, and the dead enemies equals the max enemies, we’ll want to increase the wave number and send that to the wave display. (The debug was just for me to make sure this was working).
Now we’ll just want to call this method in the enemy script whenever it gets killed by the laser or crashing into the player.
Now we have a working wave system!