스크립팅 API

설명

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

The primary Camera in the Scene. Returns null if there is no such camera in the Scene.
This property uses FindGameObjectsWithTag internally and doesn't cache the result. It is advised to cache the return value of Camera.main if it is used multiple times per frame.

//Place this script on a GameObject to switch between the main Camera and your own second Camera on the press of the "L" key
//Place a second Camera in your Scene and assign it as the "Camera Two" in the Inspector.

void Update()
{
//Press the L Button to switch cameras
if (Input.GetKeyDown(KeyCode.L))
{
//Check that the Main Camera is enabled in the Scene, then switch to the other Camera on a key press
if (m_MainCamera.enabled)
{
//Enable the second Camera
m_CameraTwo.enabled = true;

//The Main first Camera is disabled
m_MainCamera.enabled = false;
}
//Otherwise, if the Main Camera is not enabled, switch back to the Main Camera on a key press
else if (!m_MainCamera.enabled)
{
//Disable the second camera
m_CameraTwo.enabled = false;