Creating a health bar with armor
In this recipe, we are going to create a health bar, similar to the one in Implementing a linear health bar recipe, but there is an armor that protects the player. In fact, if the player is attacked, he or she will first lose the armor, then the health. To achieve this, we will use multiple Image (Script) components, both for the health bar and for the pieces of armor, and develop a script to manage the entire logic.
How to do it...
- To begin, let's create an image, so right-click on the Hierarchy panel and then UI | Image, and rename it HealthBar with Armor.
- Let's change Fill Method into Horizontal and Fill Origin into Left. Of course, we need to add the Healthbar that we have just created to Source Image. Finally, ...
Get Unity UI Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.