Having problems scripting Text

So, I have this script:

using UnityEngine;
using UnityEngine.UI;

public class MenuSumiu : MonoBehaviour {
    public float timeLeft = 10.0f;
    public GameObject tutorial;
    Text countdowntext;

    void Update()
    {
        timeLeft -= Time.deltaTime;
        countdowntext.text = "This will close in: ";

        if (timeLeft < 0)
        {
           
        }
    }
}

And I get spammed with
NullReferenceException: Object reference not set to an instance of an object
MenuSumiu.Update () (at Assets/MenuSumiu.cs:12)

Can someone help me?

You didn’t reference the Text component anywhere. You need to hook up “countdowntext” to a GameObject with the Text component on it. You declared a Text variable, but you never define it. So it’s ‘null’ all the time.

Either make it public and drag the corresponding Text into the field or find it in Start() somehow if you want it to be private.

It worked, thanks so much. :smile: