CameraFollow.cs 545 B

1234567891011121314151617181920
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class CameraFollow : MonoBehaviour {
  5. public Transform target;
  6. public float smoothing = 5f;
  7. Vector3 offset;
  8. // Use this for initialization
  9. void Start () {
  10. offset = transform.position - target.position;
  11. }
  12. // Update is called once per frame
  13. void FixedUpdate () {
  14. Vector3 targetCamPos = target.position + offset;
  15. transform.position = Vector3.Lerp(transform.position, targetCamPos, smoothing * Time.deltaTime);
  16. }
  17. }