在 GUI 标签上全局更改字体大小



我尝试在 GUI 标签上全局更改字体大小,但它给了我一个错误:

MissingFieldException: UnityEngine.GUIStyle.fonSize Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.FindExtension (IE无数'1候选人(

这是我的代码

static var myScore = 0;
static var score = 0;
static var money = 0;
static var level = 0;
static var drinks = 0;
var fontSize  : int = 20;
public var guiSkin : GUISkin;
function OnGUI()
{
GUI.skin = guiSkin;
GUI.contentColor = Color.red;
GUI.skin.label.fontSize = fontSize;
GUI.Label(Rect((Screen.width / 2) - 60,15, 200, 30), "Score: " + score);
GUI.Label(Rect((Screen.width / 2) - 60,30, 200, 30), "Money: " + money);
GUI.Label(Rect((Screen.width / 2) - 60,42, 200, 30), "Level: " + level);
GUI.Label(Rect((Screen.width / 2) - -320,25, 200, 30), "Drinks: " + drinks);
}

看起来您正在遵循一些旧教程。我建议您停止,因为您使用的是将来将被删除的旧 GUI 系统。避免任何需要OnGUI函数的东西,除非它用于编辑器插件。

您应该使用 Unity 的新 UI 系统。在这种情况下,您需要Text组件,您可以使用Text.font变量更改字体大小。有关 Unity 中的完整 UI 教程,请参阅此处。

最新更新