I’m trying to make a countdown timer for my game that, when it finishes, it changes the scene, but i keep getting this error:
here is the error:
NullReferenceException: Object reference not set to an instance of an object
NewBehaviourScript1.Update () (at Assets/scripts/Timer.cs:20)
here is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class NewBehaviourScript1 : MonoBehaviour
{
float currentTime;
public int startMinutes;
public Text currentTimeText;
// Start is called before the first frame update
void Start()
{
currentTime = startMinutes * 60;
}
// Update is called once per frame
void Update()
{
currentTimeText.text = currentTime.ToString();
}
}
Remember that the error message will tell you which line the error occurs on. In your case, it reports line 20. The only reference on this line is to currentTimeText, so you likely did not set this reference in the inspector.