private void FindFreeTarget() { if (_CurrentLane == _Path[_Path.Count - 1]) { _FreeTarget = Vector3.forward * 10000; return; } Lane endLane = _CurrentLane; while (endLane._Nodes[1].connectedLanes.Count == 1) { //check for crossroads where a road only has 1 other connection, this happens with 1 lane roads if (endLane._Nodes[1].connectedLanes[0].Parent == null) { break; } if (endLane._Nodes[1].connectedLanes[0] != _CurrentLane) { endLane = endLane._Nodes[1].connectedLanes[0]; } else { _FreeTarget = Vector3.forward * 10000; return; } } if (Vector2.Distance(endLane._Nodes[1].position, transform.position) < _CrossroadDistance && _CurrentLane._Nodes[1].parent.crossroad && _CurrentLane._Nodes[1].parent.crossroad.roadCount > 2) { if (_CurrentLane.GetLeadingVehicle(gameObject) == null && _Path[_PathIdx + 2].CanEnter() && !_CurrentCrossroad && endLane._Nodes[1].parent.crossroad.EnterCrossroad(gameObject, _Path[_PathIdx + 1])) { _CurrentCrossroad = endLane._Nodes[1].parent.crossroad; _FreeTarget = Vector3.forward * 10000; } } if (!_CurrentCrossroad) { _FreeTarget = endLane.path[endLane.path.Count - 1]; } }