Ok, here’s the problem. I’m attempting to reference the Boolean in another script attached to the same game object that the current script is running on, that will tell the new script if the alarm is raised. This would then cue a countdown timer that would begin counting down on the top of the screen.
The game object they are both attached to is called “Player”.
The code for that script is here:
private var startTime;
private var remainingSeconds : int;
private var roundedRemainingSeconds : int;
private var clockSeconds : int;
private var clockMinutes : int;
private var countDown : System.Boolean = true;
var alarmScript : ProgressBar = GetComponent(ProgressBar);
//Response time is measured in seconds, so adjust accordingly
var responseTime : int;
function Awake()
{
if(alarmScript.alarmRaised == true)
{
startTime = Time.time;
}
}
function OnGUI () {
if(alarmScript.alarmRaised == true)
{
if(countDown)
{
//Time is measured from the moment the script is called.
var guiClock = Time.time - startTime;
remainingSeconds = responseTime - (guiClock);
//This is where you would make events happen, etc, based on the clock.
if (remainingSeconds == 60)
{
print ("One Minute Left");
}
if (remainingSeconds == 0)
{
print ("Time is Over");
}
//displays the clock in 00:00 format
roundedRemainingSeconds = Mathf.CeilToInt(remainingSeconds);
clockSeconds = roundedRemainingSeconds % 60;
clockMinutes = roundedRemainingSeconds / 60;
if(clockSeconds != 0 || clockMinutes != 0)
{
timerText = String.Format ("{0:00}:{1:00}", clockMinutes, clockSeconds);
GUI.Label (Rect (400, 25, 100, 30), timerText);
}
if(clockSeconds == 0 && clockMinutes == 0)
{
countDown = false;
}
}
//Stops the countdown and displays a message once it hits 0
if(!countDown)
{
GUI.Label(Rect(400,25,100,30), "Done!");
}
}
}
However, I’m getting a null reference exception, even when using:
GameObject.Find("Player").GetComponent("ProgressBar").alarmRaised == true
The names are correct:
(The field for the script, I filled in with the “Player” game object, and yet it says no object referenced…)
However I continually get this:
Can someone help me get rid of this error?