In this step we will make the terrain generator more customizable. Instead of changing values in the source code we would like to change values in the editor.

Fortunately Unity makes it easy to add fields to the inspector of the script, simply by making fields public.

1 We actually have four variables that are responsible for the look of the terrain: the values by which we divide the x and y coordinates, and the value by which we divide the height returned from PerlinNoise().

Add four variables named Level1Step, Level2Step and Level1Div and Level2Div. And add two more variables named OffsetX and OffsetY. These variables will make it possible to move the part of the generated terrain:

using System.Collections;
using UnityEngine;

public class TerrainGenerator : MonoBehaviour
{
    public float Level1Div = 1, Level2Div = 4;
    public float Level1Step = 200, Level2Step = 50;
    public float OffsetX = 0, OffsetZ = 0;
    private float[,] _heights;
    private Terrain _terrain;
    private TerrainData _terrainData;

    // ..
}

 

2 Now change the code in GeneratePerlinTerrain() to use the new variables instead of the constants:

using System.Collections;
using UnityEngine;

public class TerrainGenerator : MonoBehaviour
{
    public float Level1Div = 1, Level2Div = 4;
    public float Level1Step = 200, Level2Step = 50;
    public float OffsetX = 0, OffsetZ = 0;
    private float[,] _heights;
    private Terrain _terrain;
    private TerrainData _terrainData;

    public void GeneratePerlinTerrain()
    {
        for (int z = 0; z < _terrainData.heightmapHeight; ++z)
        {
            for (int x = 0; x < _terrainData.heightmapWidth; ++x)
            {
                float height1 = 0;
                float height2 = 0;

                height1 = Mathf.PerlinNoise(x / Level1Step + OffsetX, 
                    z / Level1Step + OffsetZ) / Level1Div;
                height2 = Mathf.PerlinNoise(x / Level2Step + OffsetX, 
                    z / Level2Step + OffsetZ) / Level2Div;
                _heights[x, z] = height1 + height2;
            }
        }
    }

    // ..
}

After these changes you should see the new variables show up in the inspector of the script:

Try changing the values and run the scene to see the changes. Especially changing OffsetX and OffsetY will give completely different terrains.