Created
March 15, 2017 20:02
-
-
Save Problematic/c628ea237988cbed5183a225bda87188 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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