- Home /
Script loads font, how do I change the color?
I'm loading the font like this:
Font fontNormal;
GUIStyle gsNormal;
void Start()
{
fontNormal = Resources.Load("FontNameOfSomeKind", typeof(Font)) as Font;
fontNormal.material.color = new Color(1f,1f,1f); // this does nothing?
gsNormal = new GUIStyle();
gsNormal.font = fontNormal; // same with default Arial font...
gsNormal.fontSize = 50;
gsNormal.alignment = TextAnchor.MiddleCenter;
gsNormal.fontStyle = FontStyle.Normal;
}
Nothing, the text is black. Not white or any other color.
I dont use GUI Text as component, but the GUI.Box like this:
void OnGUI()
{
float width = Screen.width;
float height = Screen.height;
Rect textline = new Rect( width/2-400, 20, 800,50);
GUI.Box(textline, "here is my WHITE text - I thought?",gsNormal);
}
I think that by default new GUIStyles have all their text colours set to (0, 0, 0, 0)! You have to manually set the GUIStyle color as well as just the font color.
thanks mate, but I posted the answer already. I was addressing the wrong variable/attribute. :o)
Answer by BerggreenDK · Oct 11, 2011 at 10:47 AM
My bad.
I forgot that color is a part of the Normal attribute on a GUIStyle.
So for others who doesnt know or have forgotten like me:
gsNormal.normal.textColor = Color.White; // thats how simple it is... *sigh!*
Your answer
Follow this Question
Related Questions
How do I change the font and color of GUI text? 0 Answers
How do I change the font and color of GUI text? 1 Answer
french accent and dynamic fonts 1 Answer
New UI system 4.6, how to change font color? 2 Answers
How to change font color 4 Answers