camera switch problem

ok, so I have a problem.
what I’m trying to do is get it so when the character walks into a different section of the area, it switches the camera to a better, or at least different view. the cameras are static and don’t move.

this is the script I have right now:

var camera1 : Camera;
var camera2 : Camera;
var Start; 
	camera1.enabled = true;
	camera2.enabled = false;

function OnTriggerEnter (Cube1)
{
camera1.enabled = false;
camera2.enabled = true;
}

function OnTriggerExit(Cube1)
{
camera1.enabled = true;
camera2.enabled = false;
}

Cube1 is an invisible box that is supposed to be the mark where it switches cameras. but if thats that trigger than the script has to be on it, and nothing will happen when the character moves to it. but if the character has the script, it can’t be a trigger without adding a collider which screws everything up.
can someone please help?

you need to add the collider.

When you make the collider a trigger it doesn’t act as a collider.

function OnTriggerEnter (col : Collider) {

	Debug.Log("triggering");
	
}

function OnTriggerExit (col : Collider) {

	Debug.Log("triggering exit");
	
}

just attach something like that to your cube and it should work, then just add your other stuff.

ok, it works great now, but I have a new problem.
I need to have multiples of these areas, and when I set up a new one the code from the first one gets switched to the new one.

code for area 1:

var camera1 : Camera;
var camera2 : Camera;
var Start; 
	camera1.enabled = true;
	camera2.enabled = false;

function OnTriggerEnter(Cube1)
{
camera1.enabled = false;
camera2.enabled = true;
}

function OnTriggerExit(Cube1)
{
camera1.enabled = true;
camera2.enabled = false;
}

code for area 2:

var camera3 : Camera;
var camera4 : Camera;
var Start; 
	camera3.enabled = true;
	camera4.enabled = false;

function OnTriggerEnter(Cube2)
{
camera3.enabled = false;
camera4.enabled = true;
}

function OnTriggerExit(Cube2)
{
camera3.enabled = true;
camera4.enabled = false;
}

Keep the camera in an array and use a function like the following to change them:-

var cameras: Camera[];

function SwitchCam(newCamNum: int) {
  for (i = 0; i < cameras.Length; i++) {
    cameras[i].enabled = i == newCamNum;
  }
}

Sorry to jump in on this thread. Haven’t seen this syntax before. Andeee, I wonder if you can explain what this line is doing. I understand the cameras .enabled, but after that I’m murky. Thanks, as always. :shock:
* *cameras[i].enabled = i == newCamNum;* *