Objective: To add UI
Now I want to add basic UI which includes a score, display the weapon level, show the wave and total number of waves, the number of enemies left in a wave, and also show game over and game win text. Later I will update the font style and possibly add some additional info like for mid-level and end boss, and maybe some more weapons.
I’ll start with a UI Canvas and several text objects for the different display info. I will also use some UI images to show the weapon level. Note that some of the game objects will be set inactive and turned active on game over or game win sequences.
For the score text, I will add coin values from when picking up collectibles that are dropped by enemies, and also points for destroying enemies. I will make a public void function in the UIManager.
In the player script, I will add coins to the total amount and pass this to the UIManager.
In the Power Up script, in the OnTrigger event, I will call this Player script to add the coins to.
Finally, in the Enemy script, when the enemies are destroyed, I will pass a random score value to the Player.
Wave and Enemies
For the number of waves and enemies, I track the enemy count in the Game Manager. I also track the current wave and the total number of waves in the Spawn Scriptable Objects script.
For the weapon level, I took three images of the weapon power ups and made an image array. Then I can access the UIManager and change this image based on the player’s weapon level when it goes up or down.
Game Over and Win Messages
The last UI update for now is to create some inactive messages and set them active when the player completes a wave, when the player dies and it’s game over, and when the player completes all waves.
Now let’s see this in action.
Thank you for your time!
In the next article, I will go over adding a mid-level and final boss.