- Home /
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 got it in either language you can easily convert it to the language of your preference.
"easily" must be subjective, as syntax is my weak point and I'm still learning C#. :\
Answer by karl_ · Jan 26, 2012 at 03:14 PM
If you're using Unity's GUI, change the color property like so:
http://unity3d.com/support/documentation/ScriptReference/GUI-color.html
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:
http://unity3d.com/support/documentation/ScriptReference/GUIText-material.html
the "GUI.color" was what I needed. $$anonymous$$new it'd be something simple :). Thank you!
Is there a simple way to change to a color not on that list? I want to change $$anonymous$$e to orange.
Answer by vikingfabian-com · Aug 28, 2014 at 08:01 AM
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);
Answer by corkr900 · Aug 22, 2016 at 05:08 AM
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);
}
Your answer
Follow this Question
Related Questions
How to change color of part of a text? 1 Answer
Time.deltaTime using Hindi numbers? 1 Answer
Rotated multi-coloured text 1 Answer
How to change color via script 2 Answers
Color.white not so much white... 3 Answers