Adding a wave system to our prototype

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!




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Automation of Cloud Infrastructure using Terraform

The secret to establishing your employer brand and hiring software developers

December 6th Community Update

Simplify your developer life with Boop

Get notified by ordinary coffee machine

O-O-P-s ! I didn’t mean to objectify.

Vivaldi’s Latest Update Unlocks Even More Browser Functionality

Vivaldi's Latest Update Unlocks Even More Browser Functionality

What is GraphQl and how it differs from REST?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
GameDev Dustin

GameDev Dustin

More from Medium

Adding the speed boost powerup

Initializing A Git Repository in Unity

Magnetism in Unity Made Easy!

Using GameDevHQ’s FileBase Asset Database For HQ Models