SO as my title probably explains it all I’ll try to further explain. I have created a health bar script that is affected by enemies etc but I want to change the colour of the health bar which is currently default black(?) to red… I know this is simple cause I have done it in the past, and on a side note would like to lengthen the health bar.
As you may understand I did not write this script and cannot remember who did to give him the credit:(
Anw here is the snippet:
#pragma strict
var Health:float=300;
var maxHealth:float=100;
var maxBAR:float=100;
var HealthBarLength:float;
// This is the player's money
var Money:int=0;
function OnGUI()
{
// This code creates the health bar at the coordinates 10,10
GUI.Box(new Rect(10,10,HealthBarLength,25), "");
// This code determines the length of the health bar
HealthBarLength=Health*maxBAR/maxHealth;
//I am guessing this is what is going to be edited:o
}
function ChangeHealth(Change:float)
{
// This line will take whatever value is passed to this function and add it to curHP.
Health+=Change;
// This if statement ensures that we don't go over the max health
if(Health>maxHealth)
{
Health=100;
}
// This if statement is to check if the player has died
if(Health<=0)
{
// Die
Application.LoadLevel("gameover");
}
}
// This function checks if the player has entered a trigger
function OnTriggerEnter(other:Collider)
{
// The switch statement checks what tag the other gameobject is, and reacts accordingly.
switch(other.gameObject.tag)
{
case "Health":
ChangeHealth(25);
Destroy(other.gameObject);
break;
case "enemy":
ChangeHealth(-25);
break;
case "car":
ChangeHealth(-35);
break;
case "object":
Money+=25;
Destroy(other.gameObject);
break;
}
// Finally, this line destroys the gameObject the player collided with.
//Destroy(other.gameObject);
}