Text/font color

I just want to change my font/text color using c# in my script.
It seems simple enough but I keep seeing MUCH more complicated code out there, and not much in the way of c#, mostly in Java.

If you’re using Unity’s GUI, change the color property like so:


void OnGUI()
    GUI.color = Color.blue;
    GUILayout.Label("I'm Blue!");

If you’re talking about GUIText and 3DText, you’ll need to modify the material tint:


To make GUI.color to work, the text must have a white style. Out color = GUI.color * Style color.

GUI.color = Color.blue;
GUILayout.Label("I'm Blue!", EditorStyles.whiteLabel);

I just spent several days looking for a good solution to this, and changing GUI.color was too universal of a change to work for my application. Eventually, reading through the docs, I found this solution, which I believe may be what you’re looking for:

Let’s say you want to make a particular GUI.Label green (default is white).
To do this, you’ll have to pass a GUIStyle object into your call to GUI.Label. Some GUI elements have 3 different states (normal, Active, Focused). A label only has normal, but GUIStyle doesn’t know that. So you can set the textColor component of the normal GUIStyleState of your GUIStyle to green (or whatever color you choose), and then pass that GUIStyle into you call to GUI.Label. Example:

public static void ColoredLabel(Rect position, string text, Color textColor){
     GUIStyle style = new GUIStyle();
     style.normal.textColor = textColor;
     GUI.Label(position, text, style);