float[,] CreateHeightMap(int seed, int mapWidth, int offsetX, int offsetY) { Noise.CreateNewSimplexNoiseGenerator(seed); float[,] heightMap = new float[mapWidth, mapWidth]; // Initialize height map values for (int z = 0; z < mapWidth; z++) { for (int x = 0; x < mapWidth; x++) { heightMap[x, z] = 0f; } } // Add each height map layer together float totalMapDepth = 0f; foreach (HeightMapSettings settings in heightMapSettingsList) { float[,] layer = CreateHeightMapLayer(settings, seed, mapWidth, offsetX, offsetY); totalMapDepth += settings.mapDepth; // Determine map depth for (int z = 0; z < mapWidth; z++) { for (int x = 0; x < mapWidth; x++) { heightMap[x, z] += layer[x, z]; } } } float actualAverageMapDepth = totalMapDepth / heightMapSettingsList.Count; float averageMapDepthDifference = Mathf.Abs(actualAverageMapDepth - averageMapDepth); // Adjust map depth to obtain targeted average map depth for (int z = 0; z < mapWidth; z++) { for (int x = 0; x < mapWidth; x++) { heightMap[x, z] -= averageMapDepthDifference; } } return(heightMap); }