drakon-firestone

CameraController

Nov 25th, 2021
649
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Cinemachine;
  5.  
  6. public class CameraController : MonoBehaviour
  7. {
  8.     public Vector3[] positions;
  9.     public CinemachineVirtualCamera cam;
  10.     int activePosition = 0;
  11.  
  12.     // Start is called before the first frame update
  13.     void Start()
  14.     {
  15.         if (positions.Length == 0) return;
  16.         cam.GetCinemachineComponent<CinemachineTransposer>().m_FollowOffset =
  17.             positions[activePosition];
  18.     }
  19.  
  20.     // Update is called once per frame
  21.     void Update()
  22.     {
  23.         if (positions.Length == 0) return;
  24.  
  25.         if (Input.GetKeyDown(KeyCode.T))
  26.         {
  27.             activePosition++;
  28.             activePosition = activePosition % positions.Length;
  29.             cam.GetCinemachineComponent<CinemachineTransposer>().m_FollowOffset =
  30.                  positions[activePosition];
  31.         }
  32.     }
  33. }
  34.  
RAW Paste Data