- Home /
oops it looked like the second option it worked. There was just some sort of delay not updating my changes in the view.
Setting Color for Handle.Label in Editor
I am trying to set the color of the text the Handle.Label draws in, but it does not seem to have any effect. I see the text but it stays Gray and is barely visible in my scene.
I have tried both of these methods
void OnDrawGizmos()
{
Vector3 namePosition = new Vector3(transform.position.x, transform.position.y, 0.5f);
//version 1
Handles.color = Color.red;
Handles.Label(namePosition, transform.gameObject.name);
//version 2
GUIStyle style = new GUIStyle();
style.normal.textColor = Color.red;
Handles.Label(namePosition, transform.gameObject.name,style);
}
tldr: Go to "Window->Built In Styles and Icons to find a big list of stuff to copy off using GUIStyle style = new GUIStyle(GUI.skin.FindStyle("...")); It's just a nice way to find prexising styles visibly.
Just to say, I tried the second approach against all the GUIStyleStates i could find on GUIStyle, to no avail.
However, copying off another existing style helped: GUIStyle style = new GUIStyle(GUI.skin.scrollView);
This is a much darker font. $$anonymous$$ight not be perfect depending on your scene.
The other thing to note is that you can find loads of these, even ones with boarders. GUI.skin.button might be a bit heavy.
There's a lot of these pre-set styles in EditorStyles, and GUI.skin, so i'd jump to those definitions and see if you can find anything particularly fitting.
YO! I figured it out!
Okay, so, Go to the Window->Build In Resources pane, as mentioned before. Find a style you want to adjust. Click on the button - this will copy the name of the style into your buffer.
Go over into code and do something like [code] _VertStyle = new GUIStyle(GUI.skin.FindStyle("ProfilerPaneSubLabel")); _VertStyle.fontSize = 8; _VertStyle.name = "VertLabel"; _VertStyle.normal.textColor = Color.black;
[/code]
The key thing is to CHANGE THE NA$$anonymous$$$$anonymous$$ The handle is clearly internally looking for the original version of the thing. It won't consider it different until the name is changed.
[Edit: I might be wrong about needing to change the name. but yeah. Do the above and you're golden]
Does anybody knows why version 1 doesn't work in unity 2017 ?
There is a pramater Guistyle for the label function, make use of that.
Example:- GUIStyle style = new GUIStyle(); style.normal.textColor = Color.white;
Use it in label function as follows Handles.Label(position, someString, style);