gui background color help

I’m trying to make a stamina bar using two GUI.Box that overlap each other. The first one, is behind is a solid black, while the one is in front, which is solid blue and I’m trying to do in a way that the stamina bar (in front) shrinks every time you sprint. My problem is that I can’t seem to change the background color of the GUI.Box. Any suggestions?

Tried doing this:

	void OnGUI()
	{
	        GUI.backgroundColor = Color.black;
		
		GUI.Box(new Rect(5, 30, 60, 20), "Stamina");
		GUI.Box(new Rect(65, 30, barLength, 20), currentStamina.ToString("0"));

		GUI.backgroundColor = Color.blue;
		
		GUI.Box(new Rect(5, 30, 60, 20));
		GUI.Box(new Rect(65, 30, barLength, 20), currentStamina.ToString("0"));
	}

And because OnGUI goes on its own function, how would I update the length of the box, if I were to press the letter “C” for example?

If i remember correctly you would need to use a different style for the GUI.Box to actually see a change of the color.
However you might want to use GUI.DrawTexture instead.

For the second question something along these lines:

private void Update() {
 if(Input.GetKey(KeyCode.C)) {
  barLength--;
 }
}

A GUI.Box is black (in the default skin), so can’t be tinted blue. You will have to make your own images to use in the Box style
Check out GUISkins here

and this decent looking step-by-step
http://forum.unity3d.com/threads/113055-Creating-Custom-GUI-Skins-PART-ONE