- Home /
Creating A GUI health bar
First, I have to say that im a beginner scripter, please be patient with me thx :D. So, I tried to create a health bar for my player and I came up with this script :
public int maxhealth = 100;
public int curhealth = 100;
public float healthlength;
void Start ()
{
healthlength = Screen.width / 2f;
}
void OnGUI()
{
GUI.backgroundColor = Color.red;
GUI.Box(new Rect(10, 10, healthlength , 20),curhealth +"/"+ maxhealth);
The problem is that whenever the hp drops, the bar shortens instead of shortening the content inside. And also, I cant turn my health bar to the colour I want either.
Comment
This question has been asked and answered many times before. There are tons of tutorials to be found on the web which you can use.
Your answer
![](https://koobas.hobune.stream/wayback/20220613131519im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
How to put a health bar above enemy?C# 2 Answers
c# - void method from external class. 2 Answers
Why is my GUI pushed over to the right? 0 Answers