如何使标签中的字体大小变大?
我使用以下函数来显示文本:
function OnGUI()
{
GUI.color = Color.green;
GUI.Label(Rect(500,350,200,50),"Lose");
}
结果是:
我该如何让这段文字变大?
如何使标签中的字体大小变大?
我使用以下函数来显示文本:
function OnGUI()
{
GUI.color = Color.green;
GUI.Label(Rect(500,350,200,50),"Lose");
}
结果是:
我该如何让这段文字变大?
只需创建一个适当的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);
}
}
会导致Unity的GUI现在支持“富文本”标记。
http://docs.unity3d.com/Documentation/Manual/StyledText.html
因此,这将起作用:
GUI.Label(Rect(500,350,200,50),"<color=green><size=40>Lose</size></color>");