Simple patrol behavior.This will set the destination on the agent so that it moves through the sequence of objects in the targets array.
- See Also
- Pathfinding.Patrol
- Version
- Tested in the A* Pathfinding Project 4.1.0
using UnityEngine;
using System.Collections;
using Pathfinding;
public class PatrolExample : MonoBehaviour {
public Transform[] targets;
int index;
IAstarAI agent;
void Awake () {
agent = GetComponent<IAstarAI>();
}
void Update () {
if (targets.Length == 0) return;
bool search = false;
if (agent.reachedEndOfPath && !agent.pathPending) {
index = index + 1;
search = true;
}
index = index % targets.Length;
agent.destination = targets[index].position;
if (search) agent.SearchPath();
}
}