HEALTH BAR Unity - HEALTH SYSTEM in 100 Seconds

Опубликовано: 27 Июль 2023
на канале: Raycastly
1,650
53

Let's learn how to quickly add a health bar to our 2d platformer game in Unity. This health system is super simple to setup and is flexible.

If you get stuck, you can ask for help on our discord server! Join through this link:
  / discord  

HealthBar.cs
https://pastebin.com/TLEgh0E5

HealthManager.cs
https://pastebin.com/t5btVpH8

Free Health Bar Assets
https://opengameart.org/content/free-...

Free Assets Used in The Video & More Free Stuff:
https://bit.ly/free-game-dev-assets

1. Create an image by going Right Click then UI/Image, name it Background and attach the sprite. Do the same for border and fill layers as well
2. Select the 3 game objects and set their size to native size.
3. Create an empty parent game object called HealthBar
4. Set the children to stretch
5. Position the healthbar wherever you want
6. Feel free to play around with the colors
7. Select the fill game object and set the image type to "filled" and the fill method to "horizontal".
8. Add a slider component to the healthbar. Disable interactability, set the transition to "None" and the navigation to "None" and finally drag the Fill into the Fill Rect Slot.
9. Anchor the healthbar to the upper left corner.
10. Create or import the Healthbar.cs script and attach it to the healthbar and set the references
11. Next step is optional, create or import the HealthManager.cs script and attach it to the player and press play

Timestamps:
0:05 Creating the UI
0:54 Writing the Healthbar Script
1:24 Attaching the Healthbar Script
1:35 Writing the HealthManager Script
2:13 Attaching the HealthManager Script
2:16 Result