Horizontal health bar

There are a few different ways that a horizontal health bar can be created, but the quickest and easiest way is to scale a single axis based on percentage. When setting up a horizontal health bar in this way, it is important to ensure that the anchor is set at the position that represents a completely depleted bar.

Remember that back in Chapter 2Canvases, Panels, and Basic Layouts, we set the anchor of the health bar to the left, so we have already set the anchor correctly. We also scaled the health bar in the x direction to show what the bar would look like as it depleted.

Now, all we need to do is tie the percentage ...

Get Mastering UI Development with Unity 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.