Implementing a lives counter
This recipe teaches us how to use a Text (Script) component, along with a script, to create a counter. It is similar to the counter in the previous recipe; however, instead of keeping track of the score, here we are managing the number of lives that the player has.
How to do it...
- Like the first step in the previous recipe, we need to create a new UI text to display the number of lives. Right-click on the Hierarchy panel and then go to UI | Text. Finally, rename it to LivesCounter.
- We can also adjust the appearance, as we have done before with the ScoreCounter, so change the Font and the Font size. We can also set the Color of the text to white, and, finally, we place it in the scene through the Rect Tool, and so on.
- Ensure again that the Rich Text variable is checked in order to use styling tags.
- Next, let's create the script that manages the number of lives: click on Add Component | New Script in the Inspector, name it LivesCounterScript and then press Create...