Scripting the health bar

In this section, we will create a new script and attach it to our HUD's health bar. We will edit the script and use it to manage our Cucumber Man's health and the visible status of the HUD's health bar.

Let's start by reviewing our health bar:

  1. In the Hierarchy panel, select the HUD_Canvas | Health_Slider.

 

  1. In the Inspector panel, review the Slider (Script) component. As you can see in the following screenshot, there is a Value component with a slider at the bottom of the interface:
  1. Click the Game view tab so you can see the HUD without being in game-mode.
  2. In the Inspector panel, drag the Value slider and observe ...

Get Getting Started with Unity 2018 - Third Edition 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.