gui healthbar stupid question (changing colours:O)

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);
}

You’d want to use GUI.Color to change the tint. Be warned that it will affect ALL GUI objects. What you can do however is that you can set the color, draw the healthbar then set the color back. This will only change the color of the box.

Oh, so I see that your health bar is a box. Here is an example of what wolfhunter was talking about. :smile:

GUI.backgroundColor = Color.red;
GUI.Box(Rect(0,0,0,0).""); // BG Color for boxes and windows
GUI.backgroundColor = Color.white; //Default Color

// For Labels and drawTextures 
GUI.contentColor = Color.red;

// For GUI text and some other elements
GUI.color = Color.red;

You will have to play around a little to see what elements will change in color.

To make your health bar width jus set the var that is in the width parameter - HealthBarLength

Adjust the max var in the condition to have a bigger bar.

I didn’t quite understand what you are telling me to do:P was just trying to find a line of code that would probably do this for me:(

I tried all the suggested on top of " GUI.Box(new Rect(10,10,HealthBarLength,25), “”);" but nothing affected the colour:( any suggestions as to why? I have tried some of these in the past and it didnt work then:/

I think it’s cause you have new in front of Rect. I’m not sure, but I don’t think an instance of a GUI.Box will work.

Don’t understand:P any suggestions:smile:?