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.

more ▼

asked Mar 27, 2010 at 08:08 PM

avatar image

95 10 12 20

(comments are locked)
10|3000 characters needed characters left

5 answers: sort voted first

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.

more ▼

answered Mar 27, 2010 at 08:28 PM

avatar image

Michael La Voie
2.5k 16 24 55

Thanks, this is helpful to know.

Mar 28, 2010 at 04:35 AM Christian Stewart

Hi guys, this solutions seams to be pretty good.

I did everything you guys suggested, but it is not working.

1) I created the asset called myGuiSkin, then,

on the script: 2) public GUISkin guiSkin;

3) Then I dragged the asset to the field.

4) I put .TTF font in assets/font directory

5) I selected the desired font in the button,label and window "parts" of myGUISkin

6) didn't work, nothing changes - dont know why...

Mar 27, 2014 at 02:44 PM xpecttrum

A very important thing to note is that Resources.Load() will not load your font unless it is in a folder named "Resources"

Jun 03, 2014 at 11:46 PM Ripster
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Mar 27, 2010 at 08:39 PM

avatar image

118k 65 303 758

@Eric5h5 you have mentioned that we can scale content without importing fonts at different sizes.. As I have asked here , and no one suggested anything about GUI.matrix .. can you explain a bit how to do that?

Mar 18, 2013 at 06:13 PM moghes
(comments are locked)
10|3000 characters needed characters left

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


 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);
more ▼

answered Nov 29, 2012 at 02:44 PM

avatar image

26 2

Solution works very nicely...

     var Label2:GUIStyle = new GUIStyle(GUI.skin.GetStyle("label"));
     Label2.fontSize = 22;
     Label2.normal.textColor = Color.yellow ;
Jun 19, 2014 at 06:28 PM drudiverse
(comments are locked)
10|3000 characters needed characters left

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), "+")) {

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.

more ▼

answered Jun 09, 2012 at 09:34 PM

avatar image

31 3 3 9

(comments are locked)
10|3000 characters needed characters left

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'.

more ▼

answered Jan 23 at 01:39 PM

avatar image

50 13 11 14

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Mar 27, 2010 at 08:08 PM

Seen: 73103 times

Last Updated: Jan 23 at 01:39 PM