- Home /
Nullreferenceexception issue.
var camNum : CameraScript;
function OnTriggerEnter (otherObject:Collider){
if (otherObject.gameObject.tag == "CAM1")
{
camNum.camNum = 1;
Debug.Log("ZONE 1 ENTERED");
}
else if (otherObject.gameObject.tag == "CAM2")
{
camNum.camNum = 2;
Debug.Log("ZONE 2 ENTERED");
}
Hey guys, I keep getting a NullReferenceException: Object reference not set to an instance of an object error, the debug log points to this line as the issue. When this line is commented out, no error occurs. I've did this before and I have a feeling I've just made a stupid mistake somewhere. Any help would be appreciated.
camNum.camNum = 1;
Answer by talklittle · Jul 11, 2013 at 11:36 PM
Looks like you need to assign a value for camNum, maybe by dragging a CameraScript instance to camNum in the Unity Inspector.
Answer by RalphTrickey · Jul 11, 2013 at 11:36 PM
You're never setting camNum. You need to do something like
public void Awake() {
// Get Track Controls
leftTrack = GameObject.Find(gameObject.name + "/Lefttrack").GetComponent<MoveTrack>();
}
Your answer
Follow this Question
Related Questions
How do I count laps for AI horses in a horse racing game? 1 Answer
I dont know why im getting a null reference exception 1 Answer
Dictionary becomes null unexpectedly when using a custom inspector 2 Answers
groundcheck function returns a NullReferenceException error when the player is airborne 1 Answer