// add before update
// variable to hold the color you want to use
Color myTextColor;
function Start()
{
// set the color to something
myTextColor = Color.green;
}
// do something => change color
myTextColor = Color.red;
function OnGUI()
{
// set color to be used in drawing the box
GUI.color = myTextColor;
GUI.Box(new Rect(10, 10, 90, 25), "Hunger:" + timer.ToString("0"));
}
I highly recommend you look at the new UI system and move away from trying to figure out the old legacy OnGUI system. If you are just starting out it’ll be far simpler to learn.
I think unitys legacy OnGUI system is far simpler for a beginner, it might be, because I used to the, with canvas it’s harder to create ui elements and harder to manipulate them. It is more professional than easier.