Wave Spawner: The Final Part

Ryan McCoach
3 min readAug 8, 2021

In the last article I mentioned it was the last, but I still wanted to add a few things before calling it done. I am going to add the following features to the Wave Spawner

  1. Allow the able to assign different enemy types for each wave.
  2. Crate a UI display that shows the Countdown time and Wave name.

In being able to assign different enemy types for each wave will we have to update the Wave Class by making the enemy an array.

We just need to make one minor adjustment in the script by updating the SpawnEnemy method from just the enemy to the current index of the enemy array. Now, the FOR LOOP is still cycling through the wave count but I could probably just change it to _wave.enemy.length. This will have it loop through each of the enemy objects in the array that is created in the Inspector and not having to match the wave count with the enemy length. I am just going to keep it because it works as is.

In creating the UI for the Wave Countdown and Name we will create to Text objects on the Canvas and declare these objects in the script and assign them in the Inspector.

In the UI script, we are going to create two methods that will display the Wave Name and Countdown. Both will need a parameter with the Name method needing a string and the Countdown needing a float.

In updating the text on the Canvas we just need to appendage both wave name and countdown variable with .text. Then, set an empty quotations plus the parameter which we will use pass in the corresponding variables when we call the method in the Wave Spawner script. The Wave Countdown we need to add an (int) to convert to the float to an integer.

In the Wave Spawner script, we need a handle on the UIManager so we declare a variable and assign the UI Manager in the Inspector.

Looking at the script where the wave countdown is actually counting down, we want to call both methods to display the wave countdown and name. We will need an argument so we pass in the waveCountdown and currentWaveName. We want this text to disappear once it gets to 0, so perform a check to see if the countdown is less than 0 and if it is we will disable those UI Text by using .enabled = false.

The last thing we will need to do is enable those UI Text to make them reappear when the the next wave is called and the new wave countdown begin.

Hopefully this is helpful! Cheers!