unity 2d switch between cameras

im making a 2d game, but i have a one problem. i want the camera to switch to another camera if the player runs off the first one.

my MainCamera has the tag MainCamera and the second camera is called Camera2 with the tag Camera2.

I have tried this to test if the camera switches but it says that “;” is expected at the var cam1 : MainCamera;

var cam1 : MainCamera;
 var cam2 : Camera2;
 function Start() {
     cam1.enabled = true;
     cam2.enabled = false;
 function Update() {
     if (Input.GetKeyDown(KeyCode.C)) {
         cam1.enabled = !cam1.enabled;
         cam2.enabled = !cam2.enabled;

Any help is much appriciated!

I’m not a JS programmer, but I think you have to write:

//Assign these variables in the inspector:
var cam1 : Camera;
var cam2 : Camera;