As I said in the previous article, we will be creating a Game Over display for our game in this article. It is not difficult to do, so this will be a relatively short article.
First, we will add a text element to the game under Canvas. We do this by right-clicking on the Canvas in the hierarchy and going down to UI > Text. We will change the name of the Text element to Game_Over_text, and then in the Text field, we’ll change it to “GAME OVER” in all caps.
Next, we change the color to white and make sure to select Overflow for both boxes, so it doesn’t cut off our text. Then we can enlarge the text and place it in the center of the screen, as shown below.
Then in our UIManager script, we need to get a handle to our game over text object. We do this like below.
Now, in our Start() method, we should disable the Game_Over_text object just to be safe. The following will take care of that.
Finally, in our UpdateLives method, we need to add a check to see if our _currentLives is zero. If so, we will enable the Game_Over_text object.
Now, once we save and let Unity compile, we can play our game and see that we get a nice GAME OVER display in the middle of our screen once we lose all three lives.
I hope you enjoyed this and found it helpful. So until next time, I wish you all the best of luck on your coding journey.