ines
ines

Reputation: 117

Change font size globally on GUI label

I try to change the font size globally on my GUI labels but it give me an error:

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

This is my code

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

Upvotes: 1

Views: 1195

Answers (1)

Programmer
Programmer

Reputation: 125245

It looks like you are following some old tutorial. I suggest you stop because you are using old GUI system that will be removed in the future. Avoid anything that requires the OnGUI function unless it for Editor plugin.

You should be using Unity's new UI system. In this case you need the Text component and you can change the font size with the Text.font variable. See this for full UI tutorial in Unity.

Upvotes: 2

Related Questions