Skip to content

Create a health bar that hovers over the player and enemies using UI Toolkit

License

Notifications You must be signed in to change notification settings

scottdd204/create-healthbar-ui-toolkit

 
 

Repository files navigation

View the entire tutorial on What Up Games.

Create a health bar that hovers over the player with UI Toolkit

It’s very important to provide the player with status updates on how a character is doing. There’s a wide array of scenarios where this is applicable, but two very common ones are a health bar or a status meter. I recently implemented this behavior in my own game as a status bar that increases over time to show when a guard is becoming more and more alert to your actions. This tutorial will go over the same mechanics that I used to create a runtime bar, but apply them to a health bar that hovers over the player and enemies.

Example

Learning Outcomes

There are two ways that you can achieve this within your game. This tutorial will only focus on one of the techniques - which is translating a position from world space to screen space. By the end of this tutorial you will be able to:

  1. Understand the difference between your two options.
  2. Design a health bar UI using the UI Builder tool.
  3. Add a runtime UI to your game.
  4. Manipulate the UI by converting world point to screen point.
  5. Toggle the visibility of a visual element.

Prerequisites

  1. You will need Unity 2020.3 LTS or later to follow along.
  2. This tutorial assumes you already have basic knowledge of Unity and intermediate knowledge of C#.
  3. Basic understanding of UI Toolkit and UI Builder.

Tutorials may work with earlier versions. The version referenced is the on I used.

Resources

  1. “Official” UI Toolkit Runtime documentation

Additionally, this project uses the following free assets (thanks guys!):

  1. Low Poly Water by Ebru Dogan
  2. Pirate Kit by Kenney

About

Create a health bar that hovers over the player and enemies using UI Toolkit

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 79.6%
  • ShaderLab 20.4%