- Home /
need help with GUI healthbar
I have a want a healthbar in my game but i dont now how to make it can you plz help me. the health script is:
var health = 100.0; var dieDuration = 0;
function ApplyDamage( amount : float ) {
health -= amount;
if (health < 1) { Die(); } else { // <- (play "hurt" animation & sound here) }
}
function Die() {
// <- (play "die" animation & sound)
yield WaitForSeconds( dieDuration );
Application.LoadLevel(Application.loadedLevel);
}
and the damage script is:
var damage = 10;
function OnTriggerEnter (hit : Collider) {
if(hit.gameObject){
hit.gameObject.BroadcastMessage("ApplyDamage",
damage,
SendMessageOptions.DontRequireReceiver);
}
}
I want a green healthbar that change to yellow when my character have 50 health and that change to red when the character have 15 health left.
Thx // Dummy7307
It would be much easier to help if you format your code...
All you have to do is select the text that is code and click the button that looks like ones and zeros.
Unformatted code makes baby Jesus cry.
Answer by AngryOldMan · Mar 29, 2011 at 06:38 PM
What a relevant name. There is already around 50 questions eg. this on this site with an answer that explains exactly what you want to do not to mention a butt load of tutorials that pop up if you use this magical search engine called google. Start off with some GUI literature to get you started you could also look at this GUI Guide but most of all you can research a question before asking it. The fact that there is this many and you have failed to find any shows that you really don't have two stones about you to look for an answer.
hi, i was trying to figure out how to make a healthbar. i found this.
i searched on google and found nothing.
your "this" link doesnt work
i already read the script reference for gui
Don't shoot down good answers, he was merely pointing out that you should try to help yourself before you ask others to help you.
P.S. Please don't tell us my first link doesn't help, on the results are links to a youtube step by step tutorial on what you need.
Your answer
Follow this Question
Related Questions
Health Bar Only For Falling Damage 2 Answers
Health Bar Centering 4 Answers
Creating a Lifebar with simple GUI in C# 3 Answers
2D GUI Group moving with players. 1 Answer
Inverse health bar 2 Answers