1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using UnityEngine;
- using System.Collections;
- namespace Pathfinding {
-
-
-
-
-
-
-
-
-
-
- [UniqueComponent(tag = "ai.destination")]
- [HelpURL("http://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_patrol.php")]
- public class Patrol : VersionedMonoBehaviour {
-
- public Transform[] targets;
-
- public float delay = 0;
-
- int index;
- IAstarAI agent;
- float switchTime = float.PositiveInfinity;
- protected override void Awake () {
- base.Awake();
- agent = GetComponent<IAstarAI>();
- }
-
- void Update () {
- if (targets.Length == 0) return;
- bool search = false;
-
-
- if (agent.reachedEndOfPath && !agent.pathPending && float.IsPositiveInfinity(switchTime)) {
- switchTime = Time.time + delay;
- }
- if (Time.time >= switchTime) {
- index = index + 1;
- search = true;
- switchTime = float.PositiveInfinity;
- }
- index = index % targets.Length;
- agent.destination = targets[index].position;
- if (search) agent.SearchPath();
- }
- }
- }
|