public void SetNextDestination() { if (isReturning) { if (positionHistory.Count > 1) { move.SetDestination(positionHistory[positionHistory.Count - 2], DestinationType.EMPTY); } return; } int repetition = 0; Vector3 nextDestinaton; do { if (repetition > 10) { nextDestinaton = (anthill.transform.position - transform.position).normalized * nextPathDistance; break; } nextDestinaton = moveGenerator.GetNextDestination(); repetition++; } while (!moveValidator.CanMove(nextDestinaton)); move.SetDestination(nextDestinaton, DestinationType.EMPTY); }