Point.cs 974 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Point : MonoBehaviour
  5. {
  6. public Transform uiRoot;
  7. public Transform canvas;
  8. public Transform target;
  9. //旋转距离
  10. public float targetDistance = 2.0f;
  11. //是否到达旋转的距离
  12. private bool arriveDistance = false;
  13. private void Update()
  14. {
  15. if (arriveDistance)
  16. {
  17. transform.RotateAround(target.position, Vector3.up, Time.deltaTime * 20);
  18. transform.LookAt(target);
  19. }
  20. else
  21. {
  22. float distance = Vector3.Distance(transform.position, target.position);
  23. if (distance <= targetDistance)
  24. {
  25. arriveDistance = true;
  26. }
  27. else
  28. {
  29. transform.position = Vector3.Lerp(transform.position, target.position, Time.deltaTime);
  30. arriveDistance = false;
  31. }
  32. }
  33. }
  34. }