123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using DG.Tweening;
- 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;
- void OnEnable()
- {
- // 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.position = 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.position = m_TargetPos;
- m_TargetIndex = 1;
- StartCoroutine(PlayAni());
- }
- }
- private void WalkGoto()
- {
- transform.DOMove(Targrt.position, Vector3.Distance(transform.position, Targrt.position)*0.5f).SetEase(Ease.Linear).OnComplete(()=> {
- m_TargetIndex++;
- if (m_TargetIndex < Points.Count)
- {
- m_TargetPos = Points[m_TargetIndex];
- Targrt.position = m_TargetPos;
- transform.LookAt(Targrt.position);
- WalkGoto();
- }
- 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);
- WalkGoto();
- yield return new WaitForSeconds(10f);
- gameObject.SetActive(false);
- }
- }
|