Advertisement
amosl

Cinemachine Camera Driver

May 19th, 2019
1,106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using UnityEngine;
  2. using Cinemachine;
  3.  
  4. /// <summary>
  5. /// Helper class for a Cinemachine virtual camera
  6. /// </summary>
  7. public class CamDriver
  8. {
  9.     private CinemachineVirtualCamera vcam;
  10.     private CinemachineFollowZoom followZoom;
  11.    
  12.  
  13.     /// <summary>
  14.     /// Constructor
  15.     /// </summary>
  16.     /// <param name="camObj"></param>
  17.     public CamDriver(GameObject camObj)
  18.     {
  19.         InitializeFromGameObject(camObj);
  20.     }
  21.  
  22.  
  23.     private void InitializeFromGameObject(GameObject camObj)
  24.     {
  25.         if (camObj != null) {
  26.             vcam = camObj.GetComponent<CinemachineVirtualCamera>();
  27.             followZoom= camObj.GetComponent<CinemachineFollowZoom>();
  28.         }
  29.  
  30.     }
  31.  
  32.     public void SetTarget(Transform trackNode)
  33.     {
  34.         vcam.Follow = trackNode;
  35.         vcam.LookAt = trackNode;
  36.     }
  37.  
  38.     public void ZoomTo(float destSize, float duration = 0)
  39.     {
  40.         followZoom.m_Damping = duration;
  41.         followZoom.m_Width = destSize;
  42.     }
  43.  
  44.  
  45.     public void Shake(float amount, float duration)
  46.     {
  47.         // TODO
  48.     }
  49.    
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement