- Home /
Active camera on Start
I have two cameras in my scene; one in first person and the other in third person. I want the first person camera (tagged as MainCamera) to be the active camera when the game starts. Once the player hits a trigger, the second camera should then become active. I cannot seem to figure out how to disable the second camera when starting. How do I ensure that only the main camera is active when starting?
I'm having a similar problem where the $$anonymous$$ainCamera tag isn't working for assigning the first camera. $$anonymous$$y current workaround is to disable all the other cameras so that only one camera component is enabled at a time. Still, I'd like to know if there's a better way to do this.
Both should probably stay tagged $$anonymous$$ainCamera. This tag is used for Camera.main, and it only finds active cameras.
Answer by Waz · Aug 25, 2011 at 03:21 PM
Simply set the GameObject inactive in the scene - the little checkbox top-left in the Inspector.
Then to swap cameras:
camera1.gameObject.active = false;
camera2.gameObject.active = true;
If you want to transition between the two cameras, you will be better with just one camera (which you move between two locations).
If you´re instantiating prefabs you have to set the ones you don´t want to be active through code as well, because every prefab+it's children gets instantiated as active=true.
You can also set just the Camera component to be inactive. That should work for prefabs as well.