Camera help

I am building a roller ball like game and what I want is that the ball rolls up a ramp with one camera on it and when it hits the platform at the top it causes it to change cameras to a differnt one and when it go back to the bottom one it go back to that one.

I have made this code but it dont seem to work atm.

function OnTriggerEnter (other : Collider) {

camera1.gameObject.active = false;
camera2.gameObject.active = true;

}

and my cameras are called camera1, and camera2 but i get the error

Assets/Upperlevel.js(): BCE0005: Unknown identifier: ‘camera1’.

Assets/Upperlevel.js(): BCE0005: Unknown identifier: ‘camera2’.

You’re confusing object name with variable name: you named one camera as “camera1”, but this didn’t create a variable called camera1.

You must declare the variables camera1 and camera2, then drag your cameras to these variables:

var camera1: Camera; // drag camera1 to this variable...
var camera2: Camera; // and camera2 to this one

function OnTriggerEnter (other : Collider) {

    camera1.gameObject.active = false;
    camera2.gameObject.active = true;
}

You need to declare the variables ‘camera1’ and ‘camera2’ before you use them! At the top of your script, put

var camera1 : GameObject;
var camera2 : GameObject;

Then assign them by dragging the gameObjects from the hierarchy onto the component in the inspector.

In this case, it would probably be better for you to use

var camera1 : Camera;
var camera2 : Camera;

and then when you want to enable/disable them,

camera1.enabled = true;
camera2.enabled = false;

or however you want to do it.