Camera Follow Script on Unity
Bellow is a Script that you can add to your 3D Game to create a camera follow.
The camera will follow your camera smoothly and effectively.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Assertions;
public class CameraFollow : MonoBehaviour { [SerializeField] Transform target; [SerializeField] float smoothing = 5f;
Vector3 offset;
void Awake (){ Assert.IsNotNull (target); }
// Use this for initialization void Start () {
offset = transform.position - target.position; } // Update is called once per frame void Update () {
Vector3 targetCamPos = target.position + offset; transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime); } }