public void GenerateMap()
    {
        float[,] noiseMap = Noise.GenerateNoise(mapWidth, mapHeight, seed, noiseScale, octaves, persistance, lacunarity, offset);

        Color[] colorMap = new Color[mapWidth * mapHeight];
        for (int x = 0; x < mapWidth; x++)
        {
            for (int y = 0; y < mapHeight; y++)
            {
                float currentHeight = noiseMap[x, y];
                for (int i = 0; i < regions.Length; i++)
                {
                    if (currentHeight <= regions[i].height)
                    {
                        colorMap[y * mapWidth + x] = regions[i].color;
                        break;
                    }
                }
            }
        }

        TerrainDisplay display = FindObjectOfType <TerrainDisplay>();

        if (drawMode == DrawMode.NoiseMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(noiseMap));
        }
        else if (drawMode == DrawMode.ColorMap)
        {
            display.DrawTexture(GenerateTexture(colorMap));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            display.DrawMesh(MeshGenerator.GenerateMesh(noiseMap, meshHeightMultiplier, meshHeightCurve), GenerateTexture(colorMap));
        }
        else if (drawMode == DrawMode.Terrain)
        {
            display.DrawTerrain(TerrainGeneration.GenerateTerrain(terrainData, noiseMap), regions);
        }
    }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        TerrainGeneration terrain = (TerrainGeneration)target;

        if (GUILayout.Button("Generate"))
        {
            terrain.ClearTerrain();
            terrain.GenerateTerrain();

            // Sets Terrain Chunks to be navigation static
            for (int i = 0; i < terrain.transform.childCount; ++i)
            {
                GameObjectUtility.SetStaticEditorFlags(terrain.transform.GetChild(i).gameObject, StaticEditorFlags.NavigationStatic);
            }
        }
        if (GUILayout.Button("Clear"))
        {
            terrain.ClearTerrain();
        }
    }