Creating the UI Text Object
- Much like the Score_text, at the top-left of the hierarchy, click the +, down to UI, then Text.
- Rename it “Game_Over_text.
- Position the text to 0, 0, 0.
- In the Text component, set the text to “GAME OVER”, set the font size to 50, the alignment to the middle, set both horizontal and vertical to “overflow”, and the color to white.
- At the top-left of the inspector, click the checkbox, which turns the text off.
Basic GAME OVER Behavior
Today everything will be in the UIManager script!
- Add variable — [SerializeField] private Text _gameOverText;
- Link the Game_Over_text to the script component in Canvas.
- In Start(), add: _gameOverText.gameObject.SetActive(false);
This makes sure the game does not start with the GAME OVER display on.
- Head to the method = UpdateLives(int currentLives)
- Add the if statement:
- If the Player’s lives reach 0, then make the GAME OVER active.
Flickering GAME OVER Behavior
Time to use some coroutines to choreograph events!
- Add the new IEnumerator method above.
- By making it false first, then it gives it a half second to show up so it’s not so abrupt.
- Then start the coroutine in our new if statement in UpdateLives():
Now test it, it‘s starting to look more like a retro space shooter!
That was how to make a flickering GAME OVER display on your UI! Next, I will go over how to make a starting screen to get our player ready to fight!
Thank you for your time!