123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class IrobotMove : MonoBehaviour
- {
- public Transform Targrt;
- private List<Vector3> m_Points;
- public List<Vector3> Points
- {
- get { return m_Points; }
- set { m_Points = value; }
- }
- public float Speed = 1f;
- private Vector3 m_TargetPos;
- private int m_TargetIndex;
- private bool m_IsWalk;
- private Animator m_Animator;
- private void Start()
- {
- m_IsWalk = false;
- m_Animator = GetComponent<Animator>();
- if (Points.Count > 0)
- {
- transform.localPosition = Points[0];
- transform.LookAt(API_GSXR_Slam.GSXR_Get_Head().position);
- transform.localEulerAngles = new Vector3(0, transform.localEulerAngles.y, 0);
- m_TargetPos = Points[1];
- Targrt.localPosition = m_TargetPos;
- m_TargetIndex = 1;
- StartCoroutine(PlayAni());
- }
- }
- private void LateUpdate()
- {
- if (m_IsWalk)
- {
- transform.Translate(Vector3.forward * Time.deltaTime * Speed, Space.Self);
- if (Vector3.Distance(transform.localPosition, Targrt.localPosition) < 0.01f)
- {
- m_TargetIndex++;
- if (m_TargetIndex < Points.Count)
- {
- m_TargetPos = Points[m_TargetIndex];
- Targrt.localPosition = m_TargetPos;
- transform.LookAt(Targrt.position);
- }
- else
- {
- gameObject.SetActive(false);
- }
- }
- }
- }
- IEnumerator PlayAni()
- {
- m_Animator.SetBool("Waving", true);
- yield return new WaitForSeconds(2f);
- m_Animator.SetBool("Waving_BackAway", true);
- yield return new WaitForSeconds(2f);
- m_Animator.SetBool("Backaway_Walk", true);
- transform.LookAt(Targrt.position);
- m_IsWalk = true;
- yield return new WaitForSeconds(10f);
- gameObject.SetActive(false);
- }
- }
|