Health Bars in Unity

Silvio Carréra
2 min readDec 6, 2020

It’s hard to find a game or even an app that doesn’t make use of bars to display information. In games, they are extremely common to present one of the player’s stats. Health (HP) being the most common one.

In Unity, there are a bunch of ways of doing a health bar. The easiest one, that’s built-in, is to add a UI Slider, remove the handle and adjust the fill rects.

Turning a Unity Slider into a Stat Bar

Sure, it works. You’ll have to do it every time or you’ll have to create a prefab for it. It will be a hassle between projects. Plus, the slider has a lot of functionality to handle input. A stat bar only displays information.

We can use the slider as a base, remove what we don’t want, and increment with functionalities that suit our needs.

One-click Creation

Well, first let’s make it so we can create a new stat bar with a click of a button.

We get a nice and chunky HP Bar.

No changes are necessary. You get a health bar ready to go.

Min Digits

In many old JRPGS, you would always see a number of digits no matter the value. This option is also built-in the Stat Bar UI.

Sweet 90s JRPG feel

Color Transition

Another cool addition is that you can customize the color based on a given percentage. So when the value drops below 50% or 25% you can change the color to signal that.

Time to use those health potions

On the script side, things are straightforward as well.

Here’s the URL for the repository.

It will make it easy for you to add as many bars as you want without cluttering your code with third-party scripts.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Silvio Carréra
Silvio Carréra

Written by Silvio Carréra

I like to write. Game Development and Game Design.

No responses yet

Write a response