Two cameras and switching

How do I set up a scene with two cameras that I will switch between and how do I reference them?

GameObject -> Create Other -> Camera -> then name the camera something like camera2.

Do I tag it too? and what do I tag it as? and how do I access it?

I've seen the following for accessing the main camera

Camera.main.enabled = false

If I create a new camera an name it camera2 can I just:

Camera.camera2.enabled = true

Thanks for any help!

first of all i should say enabling/disabling any component is possible by the enabled property. if you want to make objects (GameObjects) enabled/disabled use their active property instead. for referencing any object you can do different things:

  • use public variables and set them up in inspector
  • use GameObject.Find or Object.FindObjectsOfType. there are many different methods in these two classes that they do what you want in different ways(using tags, components or names).
  • set the variables of the manager object inside the objects that you want to reference. for example you can define a static list and tell each camera to add itself to the list in it's Awake function.

Well here is something that is really simple to do, to switch between cameras, this can also be used for aiming. Here it is, i can explain how it works at end of the code.

var camera1 : Camera;

var camera2 : Camera;
private var startCamera : int = 1;

function Start ()
{
    camera1.enabled = true;
    camera2.enabled = false;
    startCamera = 1;
}

function Update ()
{
    if(Input.GetKeyDown("f") && (startCamera == 1))
    {
        startCamera = 2;
        camera1.enabled = false;
        camera2.enabled = true;
    }
    else if (Input.GetKeyDown("c") && (startCamera == 2))
    {
        startCamera = 1;
        camera1.enabled = true;
        camera2.enabled = false;
    }
}

ok the var camera1 = Camera; variable forces the slot to be a camera object the if and else if statements were checking if the key was pressed (you can change the key to anything you want), the && (startCamera == 2) (or startCamera ==1) makes the startCamera the second Camera. So thats why there is the camera_.enabled = true; (or) = false; there. You can keep this repettion when you play your game without needing to copy the gunction over and over again.