DemonShanker2/Assets/Scripts/WalkAI.cs
2014-04-30 13:48:51 -06:00

41 lines
946 B
C#

using UnityEngine;
using System.Collections;
public class WalkAI : MonoBehaviour {
private GameObject[] destinations;
public int currentDestIndex = 0;
private NavMeshAgent nva;
void Awake() {
GameObject[] allPois = GameObject.FindGameObjectsWithTag("pois");
GameObject poi1 = allPois[Random.Range (0, allPois.Length)];
GameObject poi2 = allPois[Random.Range (0, allPois.Length)];
while (poi2 == poi1) {
poi2 = allPois[Random.Range (0, allPois.Length)];
}
Debug.Log (poi1.name + "," + poi2.name);
destinations = new GameObject[2] {
poi1,
poi2
};
nva = GetComponent<NavMeshAgent>();
nva.updateRotation = false;
nva.SetDestination(destinations[currentDestIndex].transform.position);
}
public void NextDest() {
if(currentDestIndex + 1 < destinations.Length)
++currentDestIndex;
else
currentDestIndex = 0;
nva.SetDestination(destinations[currentDestIndex].transform.position);
}
}