camera detection

i want to know how to detect a camera. by the way, i have 2 cameras so i want to know which one is being used

var camera1 : Camera;

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

i know you should start this one like this. i need help with the other bit.

GameObject.GetComponents will do this easy:

function GetActiveCamera(){
var cameras:Camera[] = GameObject.GetComponents(Camera) as Camera[];
for(var cam:Camera in cameras) if(cam.enabled) return cam;
return null;
}

var Object1 : GameObject;

var Object2 : GameObject;
private var startObject : int = 1;

function Start ()
{
Object1.enabled = true;
Object2.enabled = false;
startObject = 1;
}

function Update ()
{
if(Input.GetKeyDown(“f”) (startObject == 1))
{
startObject = 2;
Object1.enabled = false;
Object2.enabled = true;
}
else if (Input.GetKeyDown(“c”) (startObject == 2))
{
startObject = 1;
Object1.enabled = true;
Object2.enabled = false;
}
}

is this right to switch objects?

how can i detect objects? i have 2 objects so i want to know which one is being used

You are basically doing that in your code example above. Store an index or a reference to the object that’s being “used”. Whatever “used” means in the context of your objects and your application. This isn’t something that Unity can define for you.

so that code i did is correct?

Well, the GameObject class doesn’t contain a variable called “enabled”. If your program compiles, it won’t do anything. A common way to hide or show an object is to disable or enable its renderer. For example:

Object1.renderer.enabled = false; // Don't render Object1

i want to switch not hide