# Changing between cameras

**URL:** https://discussions.unity.com/t/changing-between-cameras/3254
**Category:** Questions & Answers
**Tags:** Scripting
**Created:** [August 11, 2017, 7:20am UTC](https://discussions.unity.com/t/changing-between-cameras/3254 "2017-08-11T07:20:30Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![duck](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/duck/32/477465_2.png) [@duck](https://discussions.unity.com/u/duck)
#### Post date: [April 27, 2010, 4:25pm UTC](https://discussions.unity.com/t/changing-between-cameras/3254/2 "2010-04-27T16:25:39Z")

</div>

You can do either, although it’s probably simpler to switch between cameras.

To change the main camera, you can set the `active` properties of the camera gameobjects, or you can set the `enabled` properties of the camera components _on_ the gameobjects. It’s often preferable to use the enabled property, which is shown below:

[http://unity3d.com/support/documentation/ScriptReference/GameObject-active.html](http://unity3d.com/support/documentation/ScriptReference/GameObject-active.html)

> **[Unity - Scripting API: Behaviour.enabled](https://docs.unity3d.com/ScriptReference/Behaviour-enabled.html)**

`Camera.main` refers to the first _enabled_ camera tagged with `MainCamera`, so you can tag _both_ cameras with this tag, and use a simple script to toggle between them like this:

###### note: code below is not C# but, now obsolete, JS-like Unity Script

```cs
var cam1 : Camera;
var cam2 : Camera;
  
function Start() {
    cam1.enabled = true;
    cam2.enabled = false;
}
  
function Update() {
  
    if (Input.GetKeyDown(KeyCode.C)) {
        cam1.enabled = !cam1.enabled;
        cam2.enabled = !cam2.enabled;
    }
}

```

Place this script on a gameobject in your scene (for example, your player, or a new empty gameobject), and drag references to both your cameras into the `cam1` and `cam2` variables respectively.

The static variable `Camera.main` will always refer to the currently active camera out of these two.

> **[Unity - Scripting API: Camera.main](https://docs.unity3d.com/ScriptReference/Camera-main.html)**

---

_[View the full topic](https://discussions.unity.com/t/changing-between-cameras/3254)._
