Change GUI Font size and Color?

How can I change the font and color of a GUI.Label? And other GUI objects?

I'm sorry if this has bean answered before, but all I found were questions about how to change the GameObject GUIText.

You need to supply a GUIStyle along with your draw call.

GUI.Label can take a style as a third parameter.

private void OnGUI()
{
    GUIStyle myStyle = new GUIStyle();
    myStyle.font = myFont;
    GUI.Label(new Rect(10,10, 100, 30), "Hello World!", myStyle);
}

The Font must be created as a game asset and can be assigned to the script via the property inspector. It can contain a material that will specify color.

As for creating the initial Font, it is often best to find a good ttf font that you like, import that, then assign a material with the appropriate color. This site has a bunch of great references on fonts.

If you just want to change the color, you can use GUI.contentColor. (There's also GUI.color and GUI.backgroundColor.) You can scale content without having to use new styles or import fonts at different sizes by changing GUI.matrix, but it won't be pixel-perfect in that case.

First created a folder in Assets called Resources (Assets/Resources).
And there I created an Folder Fonts.

Than

void OnGUI() {
    // Create style for a button
    GUIStyle myButtonStyle = new GUIStyle(GUI.skin.button);
    myButtonStyle.fontSize = 50;
		
    // Load and set Font
    Font myFont = (Font)Resources.Load("Fonts/comic", typeof(Font));
    myButtonStyle.font = myFont;
		
    // Set color for selected and unselected buttons
    myButtonStyle.normal.textColor = Color.red;
    myButtonStyle.hover.textColor = Color.red;

    ...

    // use style in button
    bool testButtonTwo = GUI.Button(new Rect(10,10,50,50), "test", myButtonStyle);

    ...
}

If you just want to change the font and color, you can do this:

public Font font;
public Color color;

//-------------------------------

void OnGUI () {
	
	GUI.skin.font = font;
    GUI.color = color;
	
	//----ZOOM IN BUTTON----///
	
	if (GUI.Button (new Rect (10,10,64,64), "+")) {
		
		ZoomIn();
	}
}

Just make a public variable called ‘font’ and drag the one you want into the Inspector, and pick your color from the Inspector too. You can keep all of the existing layout stuff this way.

Seriously? There is no pure code solution for this problem?

For version control, I really would like to avoid anything that is not ‘hard coded’.

Pure code solution (that uses the default font):

You need to enable RichText in your style and use this:

<size=20><color=#ABC>Text</color></size>

This is the only way we styled the text for “Codey’s Lab”.

http://docs.unity3d.com/Manual/StyledText.html

If you need the flexibility use RichText:

http://docs.unity3d.com/Manual/StyledText.html

GUIStyle style = new GUIStyle ();
style.richText = true;
GUILayout.Label("<size=30>Some <color=yellow>RICH</color> text</size>",style);

We used this everywhere in “Codey’s Lab” and it is excellent if you need more control.