Skip to content

Instantly share code, notes, and snippets.

@Problematic
Created March 15, 2017 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Problematic/c628ea237988cbed5183a225bda87188 to your computer and use it in GitHub Desktop.
Save Problematic/c628ea237988cbed5183a225bda87188 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections.Generic;
public class PatrolBehaviour : MonoBehaviour {
Queue<Transform> patrolTargets;
void Start () {
patrolTargets = new Queue<Transform>();
patrolTargets.Enqueue(target1);
patrolTargets.Enqueue(target2);
// ... etc
}
void Update () {
if (patrolTargets.Count > 0) {
var target = patrolTargets.Peek();
transform.position = Vector3.MoveTowards(transform.position, target.position, step);
if (transform.position == target.position) {
patrolTargets.Dequeue();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment