How to change camera on trigger enter unity 5

Hi I am still learning unity javascript and i am trying to make it so when you walk into one collider the other cameras turn off. There are 4 in total and one collider for each. Can anyone help and also whats the best way to learn unity javascript. Thanks much appreciated.

You can break this down into a few steps:

  1. You need to write a script and attach it to some objects in your scene
  2. You need the script to detect collisions (and recognize the player?)
  3. You need the script to turn off all cameras, then enable the camera you’d like to use

To write a script, you’ll need to find a decent tutorial that covers basics. Look for something that discusses basic syntax, operators, variable declarations, functions, components, and so on. There are literally thousands of tutorials out there.

To detect collisions, or recognize which object you’re colliding with, you can again look for tutorials.

The new thing here is really that last part, where you swap cameras.

To disable all cameras, you can loop through all of the cameras in the scene:

for (var cam in Camera.allCameras) {
    cam.enabled = false;
}

Then, you can have the script turn one camera back on:

//make an inspector variable, then set it in the scene
var myCam : Camera;

//elsewhere in script, you could turn that camera on
myCam.enabled = true;

Putting that together:

//make an inspector variable, then set it in the scene
var myCam : Camera;

//later in script, in your collision function or in some function that's called from there
for (var cam in Camera.allCameras) {
    cam.enabled = false;
}
myCam.enabled = true;