using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
/*
*文件描述:
*创始人:
*创建时间:
*修改时间:
*版本:1.0
*/
public class Enemy : MonoBehaviour {
public Transform[] waypoints;//导航路径
NavMeshAgent agent;
int index = 0;//路径下标
float timer = 0f;
float waitTime = 3f;
Animator an;
void Start () {
agent = GetComponent<NavMeshAgent>();
an = GetComponent<Animator>();
agent.destination = waypoints[index].position;//导航到第一个点
}
void Update () {
if (agent.remainingDistance<0.2f)
{
an.SetInteger("Run",0);
timer += Time.deltaTime;
if (timer>=waitTime)
{
index++;
index %= 4;
timer = 0;
}
agent.SetDestination(waypoints[index].position);
}
else
{
an.SetInteger("Run",1);
}
}
}
敌人定点巡逻
最新推荐文章于 2024-11-30 20:30:07 发布