- Home /
Trying to find boolean value in another script
I'm trying to check the boolean value from another script, I've read to do this you use the get component however I'm having some trouble with this. In this script I'm trying so that if the user has collected all the items and reaches the goal the player wins. It tells me goalCheckObject hasn't been assigned a variable. Any help is appreciated.
public class Goal : MonoBehaviour {
public GameObject goalCheckObject;
PlayerController goalCheck;
// Use this for initialization
void Start () {
goalCheck = goalCheckObject.GetComponent<PlayerController>();
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other){
if (other.gameObject.name == "Marble" && goalCheck.endGoal == true ){
Debug.Log(other.gameObject.name + " entered the trigger.");
}
}
}
did you assign an object to it in the inspector?
it might be prudent to check that goalCheckObject
and goalCheck
are non-`null` before trying to access the PlayerController
component or the endGoal
bool, or at least show some kind of warning if they fail.
Your answer
Follow this Question
Related Questions
C# Boolean Doesn't Change Value 1 Answer
How to check if string array contains duplicates C# 1 Answer
Finding Distance between Angles and Points 2 Answers
C# Deserializing XML and Assigning Values 1 Answer
How to create an Idle counter ? 2 Answers