Increase text size over time c#


I’m trying to increase text size over time, but getting an int - float error with the time part.

public class Opening : MonoBehaviour {
	public GUISkin skin;
	bool title = true;
	int size = 10;
	bool closedCapOne = false;
	bool closedCapTwo = false;
	bool closedCapThree = false;
	bool closedCapFour = false;
	bool closedCapFive = false;

	void Start () {
	void Update () {
			size += 4 * Time.deltaTime; // Smooth time?
	IEnumerator Open () {
		yield return new WaitForSeconds (5);
		title = false;
	void OnGUI () { = skin;
		skin.label.fontSize = size;
			GUILayout.BeginArea(new Rect(0,0,Screen.width,Screen.height));
			GUILayout.Label("Game Title");

How would I get around this in unity?

You can make size a float and then round it to int to set the fontsize:

float size = 10;

void OnGUI () { = skin;
    skin.label.fontSize = Mathf.RoundToInt(size);

An integer and a floatingpoint number are two fundamentally different things. Intergers are the numbers { -32768 ,… -1, 0, 1, …, 32767}, floats are saved as significant digits and an exponent. Converting from int to float is simple but you can’t make an integer out of 1.5 directly. Thus you need the round to int funktion.

Nothing to do with Unity. size (and fontSize) are ints – can’t add fractions to them. Use the rounded value:

float size; // float will make the deltaTime line happy

...fontSize = (int)(size+0.5f); // rounded

The while loop in update isn’t needed – Update runs over and over already. 4*Time.deltaTime is a trick to increase by 4 points/second. Otherwise you have to guess the increase/frame that comes out to 4/second.