1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class IrobotMove : MonoBehaviour
- {
- private Transform NRCameraRig;
- 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()
- {
- // if (GameObject.Find("NRCameraRig") != null)
- NRCameraRig = OpenXRCamera.Instance.head;//GameObject.Find("NRCameraRig").GetComponent<Transform>();
- m_IsWalk = false;
- m_Animator = GetComponent<Animator>();
- 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);
- }
- }
|