In a lot of games throughout history, they had a function within the game that depicted the player’s death as a “Game Over” sequence.
This is super easy to implement into a game and I am gonna show you how!
This script will be attached to the player object…
You will have to create a UI Text object to print the words “Game Over” on your UI.
Then within your scene in Unity, you will need to reference the “Game Over” text object by dragging and dropping it into the “_gameOverText” reference box on your script.
Essentially all you are doing is:
- Creating a number variable to represent life for the player.
- Then referencing that life in order to subtract it when you take damage.
- And last, if you run out of life, destroy the player and activate the “GameOverText” object!