cameraRPG.cs 954 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Unity.VisualScripting;
  4. using UnityEngine;
  5. public class cameraRPG : MonoBehaviour
  6. {
  7. public static cameraRPG instance;
  8. public Transform focus;
  9. public float smoothTime = 2;
  10. public Vector3 offset;
  11. void Awake()
  12. {
  13. instance = this;
  14. }
  15. public void SetTarget(Transform target){
  16. focus = target;
  17. //offset = focus.position - transform.position;
  18. }
  19. public bool isPaused =false;
  20. void Update()
  21. {
  22. if(focus == null){return;}
  23. if(isPaused){return;}
  24. transform.position = Vector3.Lerp(transform.position, focus.position - offset, Time.deltaTime * smoothTime);
  25. }
  26. public void Teleport(Vector3 newLocation){
  27. transform.position = newLocation - offset;
  28. }
  29. }