public Map GenerateMap(int seed) { Map map = new Map(); map.seed = seed; Random.InitState(seed); map.areaList = new Map.Area[mapLength]; map.mapLength = mapLength; map.mapHeight = mapHeight; // Generate lengths for each area here, so that we can generate the point list float[] areaLengths = new float[mapLength]; for (int i = 0; i < mapLength; i++) { areaLengths[i] = Random.Range(areaMinMaxLength.x, areaMinMaxLength.y); } map.totalMapLength = areaLengths.Sum(); List <Vector2> allPoints = new PoissonDiscSampler ( map.totalMapLength, mapHeight, distanceBetweenPoints ).Samples().Where ( p => p.y <= mapHeight - emptyDistanceFromTopAndBottom && p.y >= emptyDistanceFromTopAndBottom ).ToList(); float xDistance = 0f; for (int x = 0; x < mapLength; x++) { Vector2 areaSize = new Vector2(areaLengths[x], mapHeight); List <Vector2> areaPoints = allPoints.FindAll ( p => p.x > xDistance && p.x < xDistance + areaSize.x ); Map.Area area = new Map.Area(); area.areaSize = areaSize; area.xOffsetFromStart = xDistance + areaSize.x / 2f; GeneratePoints(area, areaPoints); map.areaList[x] = area; xDistance += areaSize.x; } return(map); }