Creating a symbolic lives counter
This recipe teaches us how to use multiple Image (Script) components inside a script in order to create a symbolic lives counter. The number of lives are not displayed as a number, but with heart symbols on the screen. It is similar to the counter in the Implementing a lives counter recipe, but the logic to manage different icons is different.
How to do it...
- To begin, let's create a new empty game object. To do this, right-click on the Canvas object, since we want it as parent, and then Create Empty. Finally, rename it as SymbolicLivesCounter.
Tip
If there isn't the Canvas object in the scene, for example, in new scenes, we can create it by right-clicking on Hierarchy panel and then go to UI | Canvas.
- Next, click on SymbolicLivesCounter and add a new image by selecting UI | Image, and then rename the object just created as Heart1.
- Take a heart icon image, or create on our own, and import it in to our project. If our project is not set as 2D, remember...