using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
/*
*文件描述:
*创始人:
*创建时间:
*修改时间:
*版本:1.0
*/
public class Enemy : MonoBehaviour {
public Transform[] waypoints;
float timer = 0;
float waitTime = 3f;
int index = 0;
NavMeshAgent nav;
Animator an;
void Start () {
an = GetComponent<Animator>();
nav = GetComponent<NavMeshAgent>();
nav.destination = waypoints[index].position;
}
void Update () {
if (nav.remainingDistance<=0.5f)
{
timer += Time.deltaTime;
if (timer>=waitTime)
{
index++;
timer = 0;
index = index % 4;//index%=4
nav.SetDestination(waypoints[index].position);
}
}
else
{
an.SetFloat("Run", 1);
}
}
}