public void Initialise(IslandDiscoveryNode[] buoys, int owningPlayerID) { if (!aiInitialised) { OwnerPlayerID = owningPlayerID; waypoints = buoys; if (waypoints != null) { currentWaypoint = waypoints[0]; Debug.Log(currentWaypoint); if (navAgent != null) { Debug.Log(" Destination Set"); navAgent.SetDestination(currentWaypoint.transform.position); aiInitialised = true; } else { aiInitialised = false; } } else { Debug.LogError("Waypoints are null."); } } else { Debug.LogError("PatrolAI already initialised."); } }
private void Patrol() { if (navAgent.isOnNavMesh) { // Debug.Log(Vector3.Distance(transform.position, currentWaypoint.transform.position)); if (Vector3.Distance(transform.position, currentWaypoint.transform.position) <= waypointTriggerDistance) { for (int i = 0; i < waypoints.Length; ++i) { //Finds the current waypoint in the array. if (currentWaypoint == waypoints[i]) { if (i + 1 < waypoints.Length) { currentWaypoint = waypoints[i + 1]; } else { currentWaypoint = waypoints[0]; } navAgent.SetDestination(currentWaypoint.transform.position); break; } } } } }