using System.Collections; using System.Collections.Generic; using UnityEngine; public class IrobotMove : MonoBehaviour { private Transform NRCameraRig; public Transform Targrt; private List m_Points; public List 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() { if (GameObject.Find("NRCameraRig") != null) NRCameraRig = GameObject.Find("NRCameraRig").GetComponent(); m_IsWalk = false; m_Animator = GetComponent(); if (Points.Count > 0) { transform.localPosition = Points[0]; transform.LookAt(NRCameraRig.position); //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); } }