using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { Animator animator; public Transform target; public Transform man; bool finishFlag = false; private void Awake() { animator = GetComponent(); } void Start() { Invoke("WalkAndSquat", 1); } void WalkAndSquat() { EventManager.Instance.emit("StartTip"); StartCoroutine(MovePos(transform, target.position, 2)); StartCoroutine(Squat(transform, man)); } IEnumerator MovePos(Transform ts, Vector3 targetPos, float speed) { animator.SetBool("Walk", true); while (true) { yield return new WaitForFixedUpdate(); Vector3 moveDir = (targetPos - ts.position).normalized; ts.position += moveDir * Time.fixedDeltaTime * speed; Quaternion targetRotation = Quaternion.LookRotation(targetPos - ts.position); ts.rotation = Quaternion.Lerp(ts.rotation, targetRotation, 0.01f); if (Vector3.Distance(ts.position, targetPos) <= 0.1) { ts.position = targetPos; animator.SetBool("Walk", false); finishFlag = true; yield break; } } } IEnumerator Squat(Transform my, Transform ts) { yield return new WaitUntil(Finish); transform.LookAt(ts); animator.SetTrigger("Squat"); Invoke("E_OpenStep1_2", 1); } void E_OpenStep1_2(){ EventManager.Instance.emit("Step1_1"); } bool Finish() { return finishFlag; } }