Basically, the script looks at a variable found in each of the scripts mentioned in the three nested if statements and if all of the three if statements come back true, then (for now) it Logs a Win and pauses the game. Later I will attach GUI stuff to it.
The problem is the line of the first if statement is coming up as a Null Reference Exception which, according to my research, means that it is looking for a Object or Component that does not exist. Of course, the item DOES exist.
I have three goal scripts each having the boolean variable goal and each are coming up true according to my Debug.Log in the individual scripts.
goals.GetComponent(GoalScript1) is null (implying there is no such component attached)
Looking at the script sample you’ve posted, it looks like you never set goals. Perhaps you could make that variable public and set it in the inspector? Or perform some quick lookup in Awake() using GameObject.Find(), more or less like this:
function Awake()
{
goals = GameObject.Find("MyGoalsObject"); //fill in the right name
}
First, I doubt you need to check that every frame. Try taking it out of the update function and checking only when you need to!
Second, do you have 3 sperate scripts, named GoalScript1, GoalScript2 and GoalScript3? Are they attached to your object? Can you see them attached in the inspector?
Last, try this very redundant version :
var goalScript1 : GoalScript1;
goalScript1 = goals.GetComponent(GoalScript1) as GoalScript1;
Debug.Log(goalScript1.goal);
If you’re still getting a null reference, then there is no script of type GoalScript1 attached to your goals object.