IrobotMove.cs 2.2 KB

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