- Home /
Assign a Camera to a variable
I know you can have a camera as a variable, but is their a way to assign this variable for an instantiated object? Outside of Camera.main?
I want to assign the NGUI camera to a variable of an object that's instantiated in the scene, but Camera.FindObjects...doesn't seem to work in this case. I can't use GameObject.FindGameObjectWithTag("") either?
I've done a web search and couldn't find anything just yeat...I'll dig further but I also thought I'd try asking here as well.
var myCamera: Camera;
myCamera = ???
Answer by AlucardJay · Jun 28, 2014 at 02:52 AM
The Camera would be a Component of the GameObject. Find the GameObject, then access the Camera Component.
myCamera = GameObject.FindWithTag( "MainCamera" ).camera;
Your answer
![](https://koobas.hobune.stream/wayback/20220613152702im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Prefabs and variables 1 Answer
How to change main camera and access to the other scripts?? 0 Answers
Can't assign camera to variable. 2 Answers
Camera movement in a 2D? (like angry birds) 1 Answer
Resticing variables to whole numbers 3 Answers