Game handler
Now that we have all the elements in our game, we need a script that makes our character intractable with the other elements in the level, and that takes care of the level logic.
To do this, create a new C# script and name it GameHandler
under the folder Scripts
. Then, attach the script to our Player
object. Double-click on the script in order to open it.
First, we need to define a lot of variables. Let's start with two to keep track of the player's score and health:
public float health = 2; public float score = 0;
Now we need a variable to check if the game is over:
public bool gameover = false;
Finally, we need the reference to our UI elements:
public UnityEngine.UI.Text healthUI; public UnityEngine.UI.Text ScoreUI; public GameObject gameOverUI; public GameObject youWinUI;
The next step is to implement the logic behind the collision of the character with an object. This can be done by using a function called...