
Creating Lives System
Limiting the amount of deaths available for the player
Time to add in another functionality to our barebones prototype 2.5D platformer. The lives functions basically keeps track of how many times the player can screw up before a hard game over occurs.
Scripting Lives:
Similar to how to script the score system and how it updates the values to our UI manager. We can essentially follow the same structure to create the Lives system.
We start by creating the handle and value of the Lives in the player script by defining the integer value and given name. Then we create an new public method called “Damage” or whatever you desire, and place in the following code.

As you can tell, it is exactly the same as the score method, the only difference is, instead of adding say lives, we are going to be substracting them with an “minus minus”.
In the UI Manager script, we are going to update the text element of the UI whenever our player falls into oblivion and substract 1 live.

The beauty of the script is that it is very simple to understand and incorporate.
Finally, within the Player script again, we are going to define the max amount of lives within the Start Method. We reference the UI Manager script and call upon the public “Update Lives Display” method and give the integer value a number which will equal our total lives.

Back in Unity, you will see that the Lives value will update to the set total amount upon playing.
