How to switch between multiple cameras in Unity3D

Let’s say you have three cameras in your Unity3D scene. So how do you switch between them?

In this video I will show you how to do that.

Here is the code for camera switcher:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class togglecam : MonoBehaviour {

    public Camera cam1;
    public Camera cam2;
    public Camera cam3;

    public void switchcam(int x) {
        deactivateall();
        if (x == 1)
        {
            cam1.enabled = true;
        }
        else if (x == 2)
        {
            cam2.enabled = true;
        }
        else {
            cam3.enabled = true;
        }
    }

    public void deactivateall() {
        cam1.enabled = false;
        cam2.enabled = false;
        cam3.enabled = false;
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *