2017-08-26 101 views
1

我试图在全球范围内更改字体大小在我的GUI标签,但它给我一个错误:更改字体大小全局GUI标签上

MissingFieldException: UnityEngine.GUIStyle.fonSize Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.FindExtension (IEnumerable`1 candidates)

这是我的代码

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

回答

2

它看起来像你正在关注一些老教程。我建议你停下来,因为你正在使用旧的GUI系统,将来会被删除。避免任何需要OnGUI函数的东西,除非它适用于Editor插件。

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