- Home /
How to identify a different camera? Urgent
Hello how do I identify a different camera in javascript other than main for e.g
Normally I would put down something like this: Camera.main but in this scenario it wouldn't be suitable I want to use a different camera other than the main one. Thanks!
or if you its always the same camera you want to use, why not just define a variable that you drag it into a la:
var otherCam : Camera;
if it's an unusual camera not identifialble by camera.main or camera.allCameras[0] you could try whipping through the allcameras[] array with a for loop checking for the name if (camera.allcameras[number].name=="thename"){
may it also be easier to define this camera at startup or with a draggable public variable?
A Camera can be treated just like any other component in Unity. Getting a component is always a two step process (though Unity may hide the steps in some situations like dragging and dropping on a variable). Step #1: find the game object that has the component. Step #2: Use GetComponent() to get the component.
Answer by mavasher · Apr 13, 2014 at 04:07 PM
There are lots of ways to do this:
1)Define a Tag on the necessary camera in the inspector.
in script use GameObject.FindWithTag("YourTagHere")
2) Put a unique name on the camera.
in script use GameObject.Find("YourNameHere")
3) Create a public GameObject variable at the beginning of your script then in the inspector drag the camera into that public GameObject slot.