- Home /
How can I make image health bar
Can I make like this bar in Unity (custom image)
Answer by ADiSiN · May 20, 2020 at 10:36 PM
Hi!
One of the way is to first create desired image, import it inside unity and set up Texture Type to Sprite (2D and UI) to make sure that you will be able to use it as UI component.
After that done you simply create Canvas, add Image, choose your created custom image as Source Image of the Image component and set up the Image Type of it to be Filled.
You can see different options there as Fill Method and Fill Origin with which you can play around, but the Fill Amount is the one value that you will adjust to represent your heatlh.
For example, if our character has curHp and maxHp variables, then the script to adjust fill amount could look like this:
public Image hpBar;
public float maxHp;
public float curHp;
void Update()
{
hpBar.fillAmount = curHp / maxHp;
}
Don't forget that you must use namespace using UnityEngine.UI at the top of your script in order to access Image component.
Hope that helps.
Glad that it helps.
Good luck in your project!
Answer by ILikeTurtles_ · May 20, 2020 at 10:23 PM
This is Brackeys Tutorial on how to make a health bar: https://www.youtube.com/watch?v=BLfNP4Sc_iA
Your answer
Follow this Question
Related Questions
progress bar 1 Answer
Stop Timebar decrease by pressing key button 1 Answer
How to do slowly rising bar? 1 Answer
How to change Android navigation/status bar color? 0 Answers
Health Help D: 2 Answers