I am getting a NullReferenceException in the highlighted line when i run this code, even though i have initialised the variable in the other script. The reference script is a simple timer, and the error script is trying to activate it.
Reference Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Timer : MonoBehaviour
{
public float timeRemaining = 10;
public bool timerIsRunning = false;
void Update()
{
if (timerIsRunning)
{
if (timeRemaining > 0)
{
timeRemaining -= Time.deltaTime;
}
else
{
timeRemaining = 0;
timerIsRunning = false;
}
}
}
}
Error Script:
public void CMDelay(int delay)
{
terminalInputText.enabled = false;
Timer.timerIsRunning = true; //error here
Timer.timeRemaining = delay;
while (Timer.timerIsRunning == true){}
terminalInputText.enabled = true;
}