using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Move : MonoBehaviour {
public Transform [] target;
int index=0;
public float timer = 0;
//导航组件
NavMeshAgent nav;
void Start () {
nav = GetComponent<NavMeshAgent> ();
nav.SetDestination (target [index].position);
}
// 找到一个停留几秒再找下一个
void Update () {
//距离目标点有0.2的时候,计时器开始计时
if (nav.remainingDistance <= 0.2f) {
timer+=Time.deltaTime;
if (timer >= 3) {
timer = 0;
index++;
index %= target.Length;
nav.SetDestination (target [index].position);
}
}
}
}
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Move : MonoBehaviour {
public Transform [] target;
int index=0;
public float timer = 0;
//导航组件
NavMeshAgent nav;
void Start () {
nav = GetComponent<NavMeshAgent> ();
nav.SetDestination (target [index].position);
}
// 找到一个停留几秒再找下一个
void Update () {
//距离目标点有0.2的时候,计时器开始计时
if (nav.remainingDistance <= 0.2f) {
timer+=Time.deltaTime;
if (timer >= 3) {
timer = 0;
index++;
index %= target.Length;
nav.SetDestination (target [index].position);
}
}
}
}