How to set the font size of text in Unity?

别等时光非礼了梦想. 提交于 2019-12-03 03:17:01

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>");

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!