How to set main camera?

How do I set the main camera without using gameObject.active = false or true;?

3 Answers

3

Camera.main is

The first enabled camera tagged "MainCamera" (Read Only)

Therefore, you just change the tag of the camera you want to be it, and the tag of the one that had previously been it.

such simple things ;).. thanks

–

when running my scene the view is taken from a camera which is not my main camera. it is just a camera attached to a cube. my main camera has the tag "main camera" and the other camera is untagged. any ideas of why is this happening?

–

I like using (your gameobject).camera.enabled = true; to activate and deactivate cameras. This way you can keep the game objects active and just enable and disable the camera component to “switch” between cameras. (Note that now the proper syntax is to get the camera component using GetComponent)

The best and easiest way to do it… just go into another scene you have, copy the main camera, go back to the scene where you have deleted it and paste it.

It is a very simple solution, but works very well. Thanks.

–