IrobotMove.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using DG.Tweening;
  5. public class IrobotMove : MonoBehaviour
  6. {
  7. private Transform NRCameraRig;
  8. public Transform Targrt;
  9. private List<Vector3> m_Points;
  10. public List<Vector3> Points
  11. {
  12. get { return m_Points; }
  13. set { m_Points = value; }
  14. }
  15. public float Speed = 1f;
  16. private Vector3 m_TargetPos;
  17. private int m_TargetIndex;
  18. private bool m_IsWalk;
  19. private Animator m_Animator;
  20. void OnEnable()
  21. {
  22. // if (GameObject.Find("NRCameraRig") != null)
  23. NRCameraRig = OpenXRCamera.Instance.head;//GameObject.Find("NRCameraRig").GetComponent<Transform>();
  24. m_IsWalk = false;
  25. m_Animator = GetComponent<Animator>();
  26. if (Points.Count > 0)
  27. {
  28. transform.position = Points[0];
  29. transform.LookAt(NRCameraRig.position);
  30. //transform.LookAt(API_GSXR_Slam.GSXR_Get_Head().position);
  31. transform.localEulerAngles = new Vector3(0, transform.localEulerAngles.y, 0);
  32. m_TargetPos = Points[1];
  33. Targrt.position = m_TargetPos;
  34. m_TargetIndex = 1;
  35. StartCoroutine(PlayAni());
  36. }
  37. }
  38. private void WalkGoto()
  39. {
  40. transform.DOMove(Targrt.position, Vector3.Distance(transform.position, Targrt.position)*0.5f).SetEase(Ease.Linear).OnComplete(()=> {
  41. m_TargetIndex++;
  42. if (m_TargetIndex < Points.Count)
  43. {
  44. m_TargetPos = Points[m_TargetIndex];
  45. Targrt.position = m_TargetPos;
  46. transform.LookAt(Targrt.position);
  47. WalkGoto();
  48. }
  49. else
  50. {
  51. gameObject.SetActive(false);
  52. }
  53. });
  54. }
  55. IEnumerator PlayAni()
  56. {
  57. m_Animator.SetBool("Waving", true);
  58. yield return new WaitForSeconds(2f);
  59. m_Animator.SetBool("Waving_BackAway", true);
  60. yield return new WaitForSeconds(2f);
  61. m_Animator.SetBool("Backaway_Walk", true);
  62. transform.LookAt(Targrt.position);
  63. WalkGoto();
  64. yield return new WaitForSeconds(10f);
  65. gameObject.SetActive(false);
  66. }
  67. }