Advertisement
Ltven0mI

CameraFollow.cs

Feb 15th, 2017
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CameraFollow : MonoBehaviour
  6. {
  7.     public Transform m_Target;
  8.  
  9.     public float m_offsetHeight = 7;
  10.     public float m_offsetDistance = 12;
  11.     public float m_lerpTime = 0.4f;
  12.  
  13.     // Use this for initialization
  14.     private void Start ()
  15.     {
  16.         if (m_Target == null)
  17.         {
  18.             Debug.LogError("CameraFollow: Missing Target!");
  19.         }
  20.     }
  21.  
  22.     private void FixedUpdate()
  23.     {
  24.         if (m_Target != null)
  25.         {
  26.             Vector3 offset = m_Target.forward * -m_offsetDistance + (Vector3.up * m_offsetHeight);
  27.             transform.position = Vector3.Lerp(transform.position, m_Target.position + offset, m_lerpTime * Time.deltaTime);
  28.             transform.LookAt(m_Target);
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement