Integrating the UI into the game
Now that we have our enemies ready to challenge the player, let's integrate the UI that we have created in the previous chapter into the game.
In particular, we are going to see how to integrate the Lives Counter and the Money Counter since they are the two core gameplay elements.
Integrating the Lives Counter
We need to integrate the lives counter for situations such as when an enemy reaches the end of its path, the number of lives of the player is decreased. This happens in the following way: the enemy triggers a function in the Game Manager when it has reached the end, and the Game Manager updates the number of lives in the Lives Counter.
Therefore, let's start by opening our GameManagerScript
and adding another variable. This is required to store the LivesCounterScript
reference, so that we can have access to the lives of the player:
private LivesCounterScript livesCounter;
To get the reference, we can set the variable inside the Start()
function:
void...