2017-08-26 54 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教程。

相關問題