- Home /
How do you reference different cameras
It looks like there is only a Camera.main
- how do you reference other camera's? Is there no better way than GameObject.Find()?
Answer by taoa · Dec 23, 2010 at 03:48 PM
Camera.allCameras
what is 'a particular camera'? You've got them all here. If there's a special camera that has a special component in it, go though the cameras until you find the one that has said component. If you want a camera that is at a particular position, go through the cameras until you find the one at the right position... and so on.
You could name or tag your cameras differently if you want to use them for different purposes. As taoa says, you need to yourself define what makes a camera "particular". What does make it unique? What do you need it for?
say you create N camera's at runtime (relatively small number), how can you reference just one - you can't assign tag's at runtime.. is there a way to loop through the allCamera array?
I'm very sorry to say that and I hope I misunderstood your comment, but... if you don't know how to go through each element of an array, you probably should stay (well) away from scripting/program$$anonymous$$g. Besides, you definitely can apply tag names at run time. I do it all the time: gameObject.tag = "tagname";
Answer by Paulius-Liekis · Dec 23, 2010 at 08:12 AM
Yes. Declare public variable in your class and assign value in the inspector (you should see editable field for each public variable in the inspector of your object which has your script attached).
Well, then you assign it form one object/script to another in runtime.