You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.6 KiB

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<Animator>();
}
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;
}
}