View the entire tutorial on GameDev Resources.
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.
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:
- Understand the difference between your two options.
- Design a health bar UI using the UI Builder tool.
- Add a runtime UI to your game.
- Manipulate the UI by converting world point to screen point.
- Toggle the visibility of a visual element.
- You will need Unity 2020.3 LTS or later to follow along.
- This tutorial assumes you already have basic knowledge of Unity and intermediate knowledge of C#.
- Basic understanding of UI Toolkit and UI Builder.
Tutorials may work with earlier versions. The version referenced is the on I used.
Additionally, this project uses the following free assets (thanks guys!):
- Low Poly Water by Ebru Dogan
- Pirate Kit by Kenney