private void SetDestination() { if (_waypointVisited > 0) { //find next waypoint ConnectedWaypoints nextWayponit = _currentWaypoint.NextWaypoint(_previousWaypoint); _previousWaypoint = _currentWaypoint; _currentWaypoint = nextWayponit; } Vector3 targetVector = _currentWaypoint.transform.position; _navMeshAgent.SetDestination(targetVector); _traveling = true; }