Last active
December 27, 2022 22:04
-
-
Save GT3000/ed02c268fad90ed397c6c55572156e86 to your computer and use it in GitHub Desktop.
Virtual Camera Switcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using Cinemachine; | |
public class CameraController : MonoBehaviour | |
{ | |
[SerializeField] protected CinemachineVirtualCamera[] virtualCams; | |
void Update() | |
{ | |
//Select vCam 1 and deprioritize rest | |
if (Input.GetKeyDown(KeyCode.Alpha0)) | |
{ | |
foreach (var camera in virtualCams) | |
{ | |
if (camera != null) | |
{ | |
camera.Priority = 10; | |
if (camera == virtualCams[0]) | |
{ | |
camera.Priority = 11; | |
} | |
} | |
} | |
} | |
//Select vCam 2 and deprioritize rest | |
if (Input.GetKeyDown(KeyCode.Alpha1)) | |
{ | |
foreach (var camera in virtualCams) | |
{ | |
if (camera != null) | |
{ | |
camera.Priority = 10; | |
if (camera == virtualCams[1]) | |
{ | |
camera.Priority = 11; | |
} | |
} | |
} | |
} | |
//Select vCam 3 and deprioritize rest | |
if (Input.GetKeyDown(KeyCode.Alpha2)) | |
{ | |
foreach (var camera in virtualCams) | |
{ | |
if (camera != null) | |
{ | |
camera.Priority = 10; | |
if (camera == virtualCams[2]) | |
{ | |
camera.Priority = 11; | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment