the name 'scale' doesn't exist in the current context

Hi! I’m still new to this thing and I’m just watching tutorials. However, I can’t seem to find solution to this one. can you please help me.

using UnityEngine;

public class TerrainGenerator : MonoBehaviour
{

    public int depth = 20;
    public int width = 256;
    public int height = 256;

    void start ()
    {
        Terrain terrain = GetComponent<Terrain>();
        terrain.terrainData = GenerateTerrain(terrain.terrainData);
    }

    TerrainData GenerateTerrain (TerrainData terrainData)
    {
        terrainData.size = new Vector3(width, depth, height);
        terrainData.SetHeights(0, 0, GenerateHeights());
        return terrainData;
    }

    float[,] GenerateHeights ()
    {
        float[,] heights = new float[width, height];
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                heights[x, y] = CalculateHeight(x, y);
            }
        }

        return heights;
    }

    float CalculateHeight (int x, int y)
    {
        float xCoord = x / width * scale;
        float yCoord = y / height * scale;

        return Mathf.PerlinNoise(xCoord, yCoord);
    }

There’s no scale variable. You need to add one, either at the class level or inside the CalculateHeight method.
:slight_smile:

Please look at this page for how to post code properly (nicely!) on the forums: Using code tags properly - Unity Engine - Unity Discussions

Thank you for you reply! I’m sorry, I don’t think I understand what you mean. Can you point me to a thread or a tutorial wherein I can learn that?

Okay… the only thing I can think of, is to literally start at the beginning if that didn’t make sense to you.
Here: Learn game development w/ Unity | Courses & tutorials in game design, VR, AR, & Real-time 3D | Unity Learn

Start at the very first one… :slight_smile:

because the answer is you write “float scale = 2f” or whatever value you want. and you do that inside the method, or at the class level (class level would be like how you have : depth, width, height; they are outside of methods**).