FontSize

I have spent numerous amounts of time trying to comprehend how to do this;
the wiki has nothing good; nor the reference; but on google, I found this

Yet still, I was confused,
this is what I have so far.

font is the font that is uses

try Style.fontSize

Create a new unity project. Make a c# script called fontsize.cs and paste the following code in:

// c# example
using UnityEngine;
using System.Collections;

public class fontsize : MonoBehaviour {

	void OnGUI() {
		GUIStyle g = GUI.skin.GetStyle("label");
		g.fontSize = (int)(20.0f + 10.0f * Mathf.Sin(Time.time));
		GUI.Label(new Rect(10, 10, 200, 80), "Hello World!");
	}
}

As you probably know, the GUI system uses collections of styles grouped into skins. What this code does is simply grab the out-of-the-box style for the label component, and animate it’s font size. When you run the code you’ll note that the font doesn’t smoothly change size because their are not an infinite number of font sizes. This relies on the default (Arial) font being loaded and marked as dynamic. You cannot change the size of any font that’s not marked as dynamic.

So… um… can you explain line 9?
I’ve never used Mathf :frowning:

  • Mathf is the library of maths functions in Unity.
  • One of those functions is the Sin function, which, given an angle, returns the sin of that angle, which, if you recall your math lessons at school, is a number between plus and minus one.
  • Rather than use an angle, I am just passing in the time in seconds. But the sin function doesn’t know that. It just gives a a repeating number every 6 seconds or so.
  • Because fonts have sizes in the range, say, 12pt to 32pt, I’m starting off with 20, and then adding +/-10 to that. So I end up with a number between 10 and 30, which I use to scale the font.