Building a Simple Health Bar in Unity

Chad Gutterman
2 min readApr 8, 2023

--

objective: this article is going to cover how you can build your own easy to use health bar system using Unity for your player.

The only thing I have not already covered is the UI slider for Unity. It is pretty straightforward. Drag a Unity slider into your scene and check that the fill area has a red color to it. Hide the handle and check that the interactable check box is unchecked in the slider itself. Then create an empty game object and throw a C# script into it.

We will be using Unity engine UI for this.

Declare the following.

The start method sets all the values to where they need to be to start the game. Notice I set the text transform position. An easier way to do this is just make a child of the text to the parent handle.

This code gets the left and right arrows keys from the user and if the left arrow is detected the values change.

This does the same for the right arrow.

--

--