CameraFollow.cs 578 B

12345678910111213141516171819202122232425
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class CameraFollow : MonoBehaviour
  5. {
  6. public Transform playerPos;
  7. public float smooth = 8;
  8. private Vector3 offsetPos;
  9. // Use this for initialization
  10. void Start()
  11. {
  12. offsetPos = transform.position - playerPos.position;
  13. }
  14. // Update is called once per frame
  15. void Update()
  16. {
  17. Vector3 camNewPos = playerPos.position + offsetPos;
  18. transform.position = Vector3.Lerp(transform.position, camNewPos, Time.deltaTime * smooth);
  19. }
  20. }