using UnityEngine;
using System.Collections;

//this is techniqiclly a simple way point system script!
// remember to set you patrol point objects to the same y axis value other wise it will jump up, unless that is what you want it to do.

public class Patrol : MonoBehaviour {

	public Transform[] patrolPoints; //this is an array where you can have as many point as you want.
	public float moveSpeed;//this is an float variable which sets the move speed between the patrolPoints.
	private int currentPoint;//this is an integer that lets the object know where it is currently located in the array and thus the world.

	// Use this for initialization
	void Start () {

		//this sets where the position starts, but remember arrays start at zero so if you have 3 patrol points the last patrol point is 2 not 3.
		transform.position = patrolPoints[0].position;
		 
		currentPoint = 0;
	}
	
	// Update is called once per frame.
	void Update () {

		//this tells the object to go to the next patrol point in the array.
		if (transform.position == patrolPoints [currentPoint].position) {
				
			currentPoint++;

		}

		//this will loop the patrolPoints eternally.
		if (currentPoint >= patrolPoints.Length) {

			currentPoint = 0;

		}

		//this moves the object to the patrol point, and gives it a speed of real time not frame rate time.
		transform.position = Vector3.MoveTowards(transform.position, patrolPoints[currentPoint].position, moveSpeed * Time.deltaTime); 
	
	}
}
