|
|
|
|
|
|
{ |
|
|
|
_agent = agent; |
|
|
|
_isActiveAgent = _agent != null && _agent.isActiveAndEnabled && _agent.isOnNavMesh; |
|
|
|
_wayPointIndex = 0; |
|
|
|
_wayPointIndex = _wayPointIndex - 1; //Initialized to this value so we keep the right order from the waypoints list using the modulo method below
|
|
|
|
_roamingSpeed = config.Speed; |
|
|
|
_wayppoints = config.Waypoints; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
private Vector3 GetNextDestination() |
|
|
|
{ |
|
|
|
Vector3 result = _agent.transform.position; |
|
|
|
Vector3 nextDestination = _agent.transform.position; |
|
|
|
//We check the modulo so when we reach the end of the array we go back to the first element
|
|
|
|
result = _wayppoints[_wayPointIndex].waypoint; |
|
|
|
nextDestination = _wayppoints[_wayPointIndex].waypoint; |
|
|
|
return result; |
|
|
|
//Debug.Log("the next destination" + nextDestination);
|
|
|
|
return nextDestination; |
|
|
|
} |
|
|
|
} |