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.
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
namespace Level1
|
|
|
|
|
{
|
|
|
|
|
[RequireComponent(typeof(Animator))]
|
|
|
|
|
public class NPCController : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public Transform target;
|
|
|
|
|
Animator animator;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
|
|
|
|
animator = GetComponent<Animator>();
|
|
|
|
|
//GameManager.StartGame += NpcMove;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NpcMove()
|
|
|
|
|
{
|
|
|
|
|
Invoke("StartMove", Random.value * 5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StartMove()
|
|
|
|
|
{
|
|
|
|
|
StartCoroutine(MovePosByRun(transform, target.position, 1.5f));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerator MovePosByRun(Transform ts, Vector3 targetPos, float speed)
|
|
|
|
|
{
|
|
|
|
|
animator.SetBool("Run", true);
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
yield return new WaitForFixedUpdate();
|
|
|
|
|
Vector3 moveDir = (targetPos - ts.position).normalized;
|
|
|
|
|
ts.position += moveDir * Time.fixedDeltaTime * speed;
|
|
|
|
|
if (Vector3.Distance(ts.position, targetPos) <= 0.2)
|
|
|
|
|
{
|
|
|
|
|
ts.position = targetPos;
|
|
|
|
|
animator.SetTrigger("Zhanli");
|
|
|
|
|
transform.localEulerAngles = this.target.localEulerAngles;
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|