Switching Cameras

Hi there, I’ve been trying to switch between my cameras mid-game, but the same error keeps coming up. Here are the scripts I’ve been using:

var camera1 : Camera; 
var camera2 : Camera; 
//camera1 being the main camera, and camera2 being a still one that just overlooks
var IsSwitched = false;
var IsNotSwitched = true;

function Start () { 
   camera1.enabled = true; 
   camera2.enabled = false; 
} 
 
function Update () { 
   if(IsSwitched){ 
      camera1.enabled = false; 
      camera2.enabled = true; 
   } 
   if (IsNotSwitched){ 
      camera1.enabled = true; 
      camera2.enabled = false; 
   }     
}

And here is the other script, attached to an object that when touched, switches the cameras:

var ScriptHolder : SwitchCamera1;

function OnTriggerEnter(hit : Collider) {
ScriptHolder.IsSwitched = true;
ScriptHolder.IsNotSwitched = false;
Destroy(gameObject);
}

And it works just fine with switching the cameras; however, this error came up, concerning the object that is the player (the is where the script is located, but isn’t word-for-word the exact location):

NullReferenceException
ThirdPersonController.UpdateSmoothedMovementDirection () (at [script location]:105)
ThirdPersonController.Update () (at [script location]:320)

Note: I have the OrbitCamera script attached to the main camera, obviously focused upon the player object, and the ThirdPersonController script on the player.

The only problem is this error; everything else works fine. I’d like to know what I’m doing wrong here. Thanks for helping!

It looks like the problem here is you have scripts on the character controller that are looking for Camera.main either you need to set the name and tag of both your cameras to Main Camera, or modify the script that throws the error to use the current camera instead of the main camera.