Advertisement
LeeMace

Camera Switcher

Nov 29th, 2022
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CameraSwitcher : MonoBehaviour
  6. {
  7.     //get camera inputs
  8.     public Camera camera1;
  9.     public Camera camera2;
  10.  
  11.     void Start()
  12.     {
  13.         //activate default camera
  14.         camera1.enabled = true;
  15.         camera2.enabled = false;
  16.     }
  17.  
  18.     void Update()
  19.     {
  20.         //switch camera from key press
  21.         if (Input.GetKeyDown(KeyCode.Space))
  22.         {
  23.             camera1.enabled = !camera1.enabled;
  24.             camera2.enabled = !camera2.enabled;
  25.  
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement