Am i correct in understanding that the ability to change the color of an individual GUI texture in runtime (not a global tint), which was part of the old GUITexture class, is currently not part of the new UnityGUI system?
If this is the case, has anyone come across a clean workaround?
Well, you can apply the “global” tint to a single control
If you want to only color the background graphic and not the text on top, try something like this:
GUI.backgroundColor = Color.Red;
GUILayout.Button ("I'm the Red button");
GUI.backgroundColor = Color.White;
GUILayout.Button ("I'm back to normal");
Now, if you want this as a more general-purpose thing, you just extend UnityGUI… Something like this:
static function TintButton (position : Rect, text : string, tintColor : Color) {
// store the old GUI tint color.
var oldCol = GUI.backgroundColor;
GUI.backgroundColor = tintColor;
var retval = GUI.Button (position, text);
GUI.backgroundColor = oldCol;
return retval;
}
Stick this in a class, and you can now do
MyGUI.TintButton (Rect (10,10,200,40), "Why oh why does the GUI not support this out-of-the-box?", Color.Red);
hahaha. i appreciate both the humor and the help Nicholas. That should get me off and running fine for now. thanks.
Cool! This way of extending UnityGUI small pieces at a time are the way to go…
When I designed the system, I took a look at what various games did, and found they did just about everything (buttons that wobble on MouseOver? yup, animated rainbow buttons? check, random sound samples? indeed). So I focused on making a solid base that is easy to expand in small pieces for individual games.