【问题标题】:How to set the font size of text in Unity?Unity中如何设置文本的字体大小?
【发布时间】:2013-10-08 18:29:02
【问题描述】:

如何使标签中的字体变大?

我用这个函数来显示文本:

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

结果是:

我怎样才能使这个文本更大?

【问题讨论】:

    标签: unity3d unityscript


    【解决方案1】:

    只需创建一个适当的GUIStyle 并设置fontSize。将此传递给您的标签,您就可以开始了。

    所以是这样的:

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

    会导致

    【讨论】:

      【解决方案2】:

      Unity 的 GUI 现在支持“富文本”标签。

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

      这样就可以了:

      GUI.Label(Rect(500,350,200,50),"<color=green><size=40>Lose</size></color>");
      

      【讨论】:

      • 哈,这表明我没有将 Unity 的 GUI 东西用于除编辑器扩展之外的任何东西。 :) 感谢那。 +1
      • @Bart 是的,它很方便,但除了编辑器扩展和 FPS 计数器之外,我仍然不会使用即时模式 GUI。
      猜你喜欢
      • 2023-04-06
      • 2013-03-05
      • 1970-01-01
      • 1970-01-01
      • 2021-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-01
      相关资源
      最近更新 更多