Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

Unity Camera Toggler C# Script

Posted on January 25, 2021January 25, 2021 by Habibie

Are you working with more than one camera in your game?

You can work with any amount of cameras and you can switch between them easily using this very simple C# script, I call it Unity Camera Toggler.

Here is it:

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

public class CameraToggler : MonoBehaviour
{
	
	public GameObject[] Cameras;
	
	int currentCam;
	
    // Start is called before the first frame update
    void Start()
    {
        currentCam = 0;
		setCam(currentCam);
    }

    // Update is called once per frame
    void Update()
    {
        
    }
	
	public void setCam(int idx){
		for(int i = 0; i < Cameras.Length; i++){
			if(i == idx){
				Cameras[i].SetActive(true);
			}else{
				Cameras[i].SetActive(false);
			}
		}
	}
	
	public void toggleCam(){
		currentCam++;
		if(currentCam > Cameras.Length-1)
			currentCam = 0;
		setCam(currentCam);
	}
}

In this script I use array variable of cameras, so no matter how much camera do you want to use, you just add them as much as you need to the scene and refer the script to them.

Post Views: 411
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
  • Advanced Blinking Marker Script to show objects position in your game canvas
  • Ciihuy Images Merger – Fast & Easy Online Image Combiner
© 2025 ThirteeNov | Powered by Superbs Personal Blog theme