IrobotMove.cs 2.0 KB

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