Adding a wave system to our prototype

GameDev Dustin
3 min readJan 22, 2022

Let’s create a new text object on our canvas by duplicating the “Game_Over_text”, renaming it, and modifying the settings as needed.

When it looks how you like it, disable (setActive(false)) the object.

Modifying the SpawnManager script

The first thing we need to add to our SpawnManager script is a using TMPro statement, for the TextmeshPro library since that is what our New_Wave_text is.

I want there to be 5 waves, so we need to add 4 wave timings, stored as floats.

We also need to reference our New Wave text field so that we can show it when needed and update the text as well.

We’ll use Boolean values to activate each wave.

We’ll add a null check for _newWaveTextGO in our DoNullChecks() method which is called in our Start() method.

Before we forget, let’s drag our New_Wave_text GO onto our SpawnManager script component.

I’ve created the SetWaveTimes() method to start our time stamps only once the asteroid has initiated wave 1 and to pass this into a coroutine with the delay and what wave that delay is for.

Here we create the IEnumerator routine StartNextWave and control which wave is being activated.

The waitSeconds variable passed in will always be associated with the proper wave as well.

I’ve renamed my StartSpawning() method to StartSpawningWave1().

After our asteroid is destroyed, it calls this method.

We set our wave times and then set our 2ndWave to active.

Once we show our New Wave text on the screen, we don’t want it to stay there for the remainder of the game.
So we’ll need a coroutine to set the delay before deactivating it.

All the magic comes together here, in our Update() method.

We run through an if statement that will only trigger at the appropriate time because the wave is turned on and the time is greater than the delay time.

We show our New Wave text, Start a coroutine to hide the text after a delay, start an enemy spawning coroutine and turn our wave off.

The coroutine will continue to run, but if we left the startWaveActive variable as true, we’d get an enemy spawing every frame update!

And that’s it, now we have a working enemy wave system!

--

--