In this section, we are going to make it so that the player has a set number of lives. If and when the player collides with an enemy, the player will die, the scene will reset back to the start, and a life will be deducted from the player. When all the lives are gone, we will introduce the game over scene.
We will be working with the following scripts in this section:
- GameManager
- SceneManager
- Player
Let's start by revisiting the GameManager script and setting up the capability of giving and taking the player's lives away:
- Open the GameManager script and enter the following code:
public static int playerLives = 3;
At the top of the script, just after entering the class and inheritance, enter a static (meaning only one) integer type labeled playerLives...