Creating a modular coin counter
This recipe teaches us how to use a Text (Script) and Image (Script) components along with a script to create a counter with an icon. It is similar to the counters in the two previous recipes, but, instead, to keep track of the score or lives, here we manage the number of coins possessed by the player. In contrast to the first counter that doesn't have an upper bound, or like the second counter that has a maximum for lives, here, when the player has reached a certain number of coins, something will happen. For example, a life will be added and the counter starts from zero, creating modularity.
How to do it...
- As for the first step of the previous recipe, we need to create a new UI text to show the number of lives. Hence, right-click on the Hierarchy panel and then UI | Text. Finally, rename it to Modular Coin Counter.
- Let's adjust the settings to suit our needs, such as Font, Font Size, and Color, and also write in the Text variable
0
(zero). - In order...