switching cameras script problem

i have this script so when you enter a trigger that it will change cameras and when you exit it will change back to the other one this is my script:

var mainCam : Camera;
var cam2 : Camera;

function OnTriggerEnter (player : Collider) 
{
    if(player.CompareTag("Player"))
    {
        mainCam.enabled = false;
        cam2.enabled = true;
    }
}
function OnTriggerExit (player : Collider)
{
    if(player.CompareTag("Player"))
    {
        mainCam.enabled = true;
        cam2.enabled = false;
    }
}

when i saved it and attached it to the cube acting as the trigger i got this error:

ArgumentException: You are not allowed to call get_camera when declaring a variable. Move it to the line after without a variable declaration. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function. camera switch..ctor () (at Assets/my scripts/camera switch.js:1) UnityEditorInternal.InternalEditorUtility:InspectorWindowDrag(Object, Boolean) UnityEditor.DockArea:OnGUI()

How do i fix this?

i fixed it cause i'm stupid

I have a camera system that involves switching between 5 separate scripts. It works fine in the editor but in stand-alone app mode, any Application.Loadlevel functions cause a crash saying something about a violation of some sort. I’m considering trying to somehow merge all five scripts but that may or may not solve the problem.,I have a similar problem with a camera system that doesn’t just switch between two camera’s but has an additional script that switches between two sets of camera scripts. Ever since I implemented this I can’t perform any Application.Loadlevel functions in stand alone version of my project without a crash occuring. There are a total of five scripts involved so I’ll only post the script that is the mediator of the two set’s of other scripts.

var sound : AudioClip;
var soundVolume : float = 100.0;
var obja : GameObject = GameObject.Find("Main Camera2");
var objaScript : SpringFollowCamera = obja.GetComponent(typeof(SpringFollowCamera)) as SpringFollowCamera;
var objaScript2 : MouseOrbitEDIT = obja.GetComponent(typeof(MouseOrbitEDIT)) as MouseOrbitEDIT;
var objaScript3 : CamScriptSwitch2 = obja.GetComponent(typeof(CamScriptSwitch2)) as CamScriptSwitch2;
var objaScript4 : OrbitCamera = obja.GetComponent(typeof(OrbitCamera)) as OrbitCamera;
var objaScript5 : OrbitCamera2 = obja.GetComponent(typeof(OrbitCamera2)) as OrbitCamera2;
var objaScript6 : CamScriptSwitch2D = obja.GetComponent(typeof(CamScriptSwitch2D)) as CamScriptSwitch2D;

var SideView : boolean;
var FullView : boolean;

function Update(){
if (Input.GetButtonDown ("RightJoystick")){
if (sound)
		AudioSource.PlayClipAtPoint(sound, transform.position, soundVolume);
}
if (Input.GetButtonDown ("LeftJoystick")){
  if (sound)
		AudioSource.PlayClipAtPoint(sound, transform.position, soundVolume);
}

//****
if(FullView){
 objaScript.enabled = true; //SpringFollowCamera
 objaScript2.enabled = false; //MouseOrbitEDIT
 objaScript3.enabled = true; //CamScriptSwitch2
 objaScript4.enabled = false; //OrbitCamera
 objaScript5.enabled = false; //OrbitCamera2 
 objaScript6.enabled = false; //CamScriptSwitch2D
if (Input.GetButton ("RightJoystick")){ 
  
FullView = false;
SideView = true;
		}
if (Input.GetButtonDown ("RightJoystick")){ 
  
FullView = false;
SideView = true;
		}
}
//****



//****
if (SideView){
 objaScript.enabled = false; //SpringFollowCamera
 objaScript2.enabled = false; //MouseOrbitEDIT
 objaScript3.enabled = false; //CamScriptSwitch2
 objaScript4.enabled = false; //OrbitCamera
 objaScript5.enabled = true; //OrbitCamera2 
 objaScript6.enabled = true; //CamScriptSwitch2D
if (Input.GetButton ("LeftJoystick")){ 

SideView = false;
FullView = true;

		}
	}
//****