Changing between cameras

You can do either, although it’s probably simpler to switch between cameras.

To change the main camera, you can set the active properties of the camera gameobjects, or you can set the enabled properties of the camera components on the gameobjects. It’s often preferable to use the enabled property, which is shown below:

http://unity3d.com/support/documentation/ScriptReference/GameObject-active.html

Camera.main refers to the first enabled camera tagged with MainCamera, so you can tag both cameras with this tag, and use a simple script to toggle between them like this:

note: code below is not C# but, now obsolete, JS-like Unity Script
var cam1 : Camera;
var cam2 : Camera;
  
function Start() {
    cam1.enabled = true;
    cam2.enabled = false;
}
  
function Update() {
  
    if (Input.GetKeyDown(KeyCode.C)) {
        cam1.enabled = !cam1.enabled;
        cam2.enabled = !cam2.enabled;
    }
}

Place this script on a gameobject in your scene (for example, your player, or a new empty gameobject), and drag references to both your cameras into the cam1 and cam2 variables respectively.

The static variable Camera.main will always refer to the currently active camera out of these two.

Worked great thanks!

–

how could i edit this for use with a button? it works for key down but when i try to create a button to do the same function it doesn't appear?

–

can we write the script in c#? how to write it?

–

Is is possible to have two cameras running (you can access their properties etc) but you can only see through the eyes of one of the cameras?

–

That simple!

–