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;

Looks like you need to assign a value for camNum, maybe by dragging a CameraScript instance to camNum in the Unity Inspector.

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>();
}