10

How can I make the size of the font in a label larger?

I used this function to display the text :

function OnGUI()
{
    GUI.color = Color.green;
    GUI.Label(Rect(500,350,200,50),"Lose");
}

And that results in:

How can I make this text bigger?

Community
  • 1
  • 1
Akari
  • 856
  • 8
  • 21
  • 36

2 Answers2

18

Simply create an appropriate GUIStyle and set the fontSize. Pass this to your label and you're good to go.

So something like this:

using UnityEngine;
using System.Collections;

public class FontSizeExample : MonoBehaviour 
{

    GUIStyle smallFont;
    GUIStyle largeFont;

    void Start () 
    {
        smallFont = new GUIStyle();
        largeFont = new GUIStyle();

        smallFont.fontSize = 10;
        largeFont.fontSize = 32;
    }

    void OnGUI()
    {
        GUI.Label(new Rect(100, 100, 300, 50), "SMALL HELLO WORLD", smallFont);
        GUI.Label(new Rect(100, 200, 300, 50), "LARGE HELLO WORLD", largeFont);
    }
}

will result in

Bart
  • 19,692
  • 7
  • 68
  • 77
16

Unity's GUI supports "rich text" tags now.

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

So this would work:

GUI.Label(Rect(500,350,200,50),"<color=green><size=40>Lose</size></color>");
Calvin
  • 4,177
  • 1
  • 16
  • 17
  • 3
    Ha, that shows me for not using Unity's GUI stuff for anything other than editor extensions. :) Thanks for that. +1 – Bart Oct 02 '13 at 17:15
  • @Bart Yeah, it's handy, but I still wouldn't use the immediate mode GUI for anything besides editor extensions and an FPS counter. – Calvin Oct 02 '13 at 17:21