- Home /
Question by
Paikerchu13 · Jan 26, 2014 at 05:12 AM ·
c#camerainstantiateclones
How do I stop Script from making multiple Cameras?
I have a script that instantiates a camera into the scene. However, when I run it, it creates two cameras instead of one. The second one having the name Camera(Clone) in the hierarchy.
{
GameObject cam = new GameObject("Camera",
typeof(Camera),typeof(LensFlare),typeof(AudioListener),typeof(Light));
Instantiate(cam,new Vector3((x-1)/2,(x+y)/2,(y-1)/2),new Quaternion(80,0,0,90));
}
How do I fix this so I only create one camera?
Comment
Answer by DaveA · Jan 26, 2014 at 05:14 AM
You do a 'new GameObject' which adds one, then you do an Instantiate which adds another. Pick one. I think just delete the Instantiate, and set cam.transform.position and cam.transform.rotation with those numbers you want.
Thank you, I thought making a new GameObject stored the values into a variable that had to be instantiated. Didn't know it actually put it into the scene.