- Home /
Change background color of a GUI.BOX C#
Hey, ok, so my question is, why doesn't this code work for changing the background color for GUI.box:
GUI.backgroundColor = Color.red;
GUI.Box(new Rect(10,10, healthBarLength,20), currentHealth+ "/" +maxHealth);
This works fine if I use GUI.Button, so I guess it isn't possible to change the color like this in a box. But how should it be done?
Thanks in advance.
Answer by Molix · Mar 14, 2011 at 06:03 PM
It will work, but the difference is probably due to the GUIStyle being used. By default, GUI.Button uses the "button" style, and GUI.Box uses the "box" style from the active GUI.skin. If you're not seeing the difference, it'll be because of the style. Remember that the color is multiplied in, so if the item uses a lot of black, you won't see any difference.
Either use a different style for the box, or modify the existing one. $$anonymous$$ake sure it has a background texture assigned that has some non-black parts so it can be changed. If you're unsure how to change skins/styles, see the GUI tutorial; its pretty straightforward but more than I can type here :)
Your answer
Follow this Question
Related Questions
Unity Web Player backgroundcolor 1 Answer
A node in a childnode? 1 Answer
Unity 64 bit color? 0 Answers
Changing background color every time I score 0 Answers
white background mac 1 Answer