- Home /
Text color change onHover
Hi,
I'm trying to change the text color of a GUILayout.Box using the onHover text color of my skin but, for some reason, it isn't working at all.
GUILayout.Box("text", GUI.skin.GetStyle("custom_style"));
Do you know how can I do this?
Thanks in advance, André
Answer by jahroy · Sep 20, 2011 at 04:51 PM
Your code suggests that you've added a custom style named "custom_style" to a GUISkin that has been assigned in your game.
You need to assign your GUISkin in the OnGUI function, which looks something like this:
var myCustomSkin : GUISkin;
function OnGUI() { GUI.skin = myCustomSkin; }
Also, onHover only applies to toggle buttons that are in their "on" state. You want to use hover in stead.
Also, if you don't have a background image associated with the hover state, it won't work.
The states that don't have background images are ignored.
thanks jahroy.
I had already done that assignment, however I didn't know that onHover only works with Toggle. On GUILayout.Label documentation it is written:
"Labels have no user interaction, do not catch mouse clicks and are always rendered in normal style. If you want to make a control that responds visually to user input, use a Box control"
http://unity3d.com/support/documentation/ScriptReference/GUILayout.Label.html
that's why I was expecting that a Box would handle onHover events.
Regarding the background images limitation, is the use of a transparent png a valid workaround?
I remember experiencing similar expectations!
That sounds like a perfect workaround to me.
You could make it a 1 pixel image if you like.
You could use a transparent PNG as the background image as well.
Answer by Ray-Pendergraph · Sep 20, 2011 at 04:27 PM
You can set the textcolor on the GUIStyleState for the appropriate mode(s) that you need it for (probably onHover in your case). You can do this through the inspector or code.