Displaying C# Int Value to GUI

Hey all,

I’m starting a new project and I’m trying to create a date function where every seconds adds another day. So far, my code is:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class date : MonoBehaviour {
	public int day;

	void dayAdd () {
		day++;
	}

	void Start () {
		InvokeRepeating ("dayAdd", 0f, 1.0f);
	}
		}

Now I’m trying to show this int value to a UI. I haven’t found any method that particularly works for me, so I would love some help!

Thanks!

You need to reference the TextComponent, like :

public Text uiText;

drag and drop the Text object in it in the inspector, then, in Update for example, you can simply do this :

uiText.text = day.ToString();

You simply need a Text component with a RectTransform and Canvas Renderer, and ultimately a Canvas somewhere in the parent tree.

You can place that easily anywhere in your UI, but attaching it to 2D game objects is a bit harder.