GUI.skin - How to set font size and color?

Hello,

I setup a skin for use with GUI.Label. I set a colour and a size on the normal state of the Label. The color works but the size does not. Why is that?

Incidentally, i was looking over the Unity Answers site for some info on this and they suggest to use a GUI style. Doesn’t this over write the skin?

How can i set the colour and font size through a script while still using the skin?

I have the same problem. I found several thread talking about GUI Labels, but I cannot “join” all together to make a GUI.Label using custom font size and color.

I use this code, but does not work:

function OnGUI() {
	var myStyle : GUIStyle = new GUIStyle();
	myStyle.fontSize = 50;
	GUI.color = Color.white;
	GUI.Label (Rect (200, 200, 600, 100), "Creazione scenario...", myStyle);
}

In this way I get the correct font size but color is still black. If I do:

function OnGUI() {
	GUI.color = Color.white;
	GUI.Label (Rect (200, 200, 600, 100), "Creazione scenario...");
}

I get the correct color (white) but font size is small! :face_with_spiral_eyes:

Please give me an hint since I’m becoming mad!!!

Thank you for your help! :slight_smile:

Hello,

I just solved the “puzzle”!

Here the final code (I hope this could help other people!):

function OnGUI() {
    var myStyle : GUIStyle = new GUIStyle();
    myStyle.fontSize = 50;
    myStyle.normal.textColor = Color.white;
    GUI.Label (Rect (200, 200, 600, 100), "Creazione scenario...", myStyle);
}
1 Like

As you guys suffered trying to change the size os the label, I was also mad about this, searching one way to make it work through GUI Skin.

So I pulled it off with a simple “trick”. Select the correct font at the GUI Skin inspector, and the resizing (and other stuff maybe?) should work.

Cheers!

1 Like

I am using 3.3 and I have the same problem. I think there is a bug in the GUI.skin.label (or more likely my understanding on how this works)

I tried setting the font size and color, but it does not work in the inspector for GUISkin → Label (although it works for GUISkin → TextField and others)

So I though I could do it in code and tried the following in On GUI:
//Changes only color
GUIStyle localStyle = new GUIStyle(GUI.skin.label);
localStyle.normal.textColor = Color.red;
localStyle.fontSize = 12;

//Changes both color and font size
GUIStyle localStyle = new GUIStyle();
localStyle.normal.textColor = Color.red;
localStyle.fontSize = 50;

It seems that as soon as try to set the font size specifically on the label, whether in the inspector or code, it does not work. I am a bit confused on this…

I was having similar problems getting my GUILayout.Label() call to respect the value I was setting for GUISkin.Label.fontsize in the inspector.

I tried setting GUISkin.Label.font to Arial (it was previously none) and now the fontsize value is used.

Label()'s use of GUIStyle font settings does seem inconsistent with other controls.

(just re-read Rigato’s post and they have the same solution although I didn’t quite follow it first time of reading)

To my knowledge you cannot set the fontsize. Well, maybe you can, but that would just be scaling. I think you need to import the font with the desired fontsize.
Eventually scaling down is fine. Means, you import the font with ponitsize 48, and the et it to 32, 16 or whatever.
Not sure about that.

But you definatly define the fontsize for best results with import settings.

var Skin : GUISkin;

function OnGUI () {
GUI.skin = Skin;
Skin.button.fontSize = Screen.width/25;

}
This is to change the font size for “button” , “label” should be similar.

I did this for my mobile game . Hope it helps.:sunglasses:

Rigat

o Nice one Thank You.