Implementing a linear health bar
In this recipe, we are going to create a linear health bar. The health of the player will be displayed as a bar that shortens when the player's health decreases, and extends with the player's health increases. To achieve this, we will use the Image (Script) component in a different way than what we have in previous recipes, and develop a script to manage the length of the bar.
How to do it...
- First of all, we need to create our health bar, so let's open a graphic program and create it. We can create something that should looks like the following:
- Then, import it in to our project. If the project isn't set to 2D, remember ...
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.