How to create a simple UI health bar for a character in Unity game. Easy Unity 2D tutorial.

Аватар автора
Рецепты веганских супов
#unityhealth In this video I will show you how to create a simple health bar for your Unity game. TO BLAST! - My New Fun Relaxing Puzzle Game Available On Google Play Store First let&create new UI Image game object and put health bar background sprite to the source image slot of its image script component. Double click on image to get a focus. Then check preserve aspect option. Position out image at the top center holding Alt+Shift keys. Make our image bigger by changing its width. I rename this game object as HealthBarBackground. Then right click on HealthBarBackground and create new UI image. Name it heealth bar. Put health bar sprite to source image slot of Image script. Check preserve aspect option. And change health bar width so it is a bit smaller then a backgrounds one. Anchor it to the top center then focus on it and correct its position. After that go to the Image script component and change ImageType frim simple to filled. Then change fill method to horizontal. Now if we drag the fill amount slider then we can see how our image changes. We are going to change fill amount through the script. Let&add a player and a damage zone. Add RigidBody2D component to the player with gravity scale set to zero and collision detection set to continuous. Then add a circle collider to the player and to the damage zone which collider will be a trigger. Time to add some C# scripts. Take a look at health bar script. Here we have Image health bar game object, float maxHealth which...

0/0


0/0

0/0

0/0