Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

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

Discussion in 'Scripting' started by m3wtw0, Jan 4, 2018.

  1. m3wtw0

    m3wtw0

    Joined:
    Jan 4, 2018
    Posts:
    2
    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.

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class TerrainGenerator : MonoBehaviour
    4. {
    5.  
    6.     public int depth = 20;
    7.     public int width = 256;
    8.     public int height = 256;
    9.  
    10.     void start ()
    11.     {
    12.         Terrain terrain = GetComponent<Terrain>();
    13.         terrain.terrainData = GenerateTerrain(terrain.terrainData);
    14.     }
    15.  
    16.     TerrainData GenerateTerrain (TerrainData terrainData)
    17.     {
    18.         terrainData.size = new Vector3(width, depth, height);
    19.         terrainData.SetHeights(0, 0, GenerateHeights());
    20.         return terrainData;
    21.     }
    22.  
    23.     float[,] GenerateHeights ()
    24.     {
    25.         float[,] heights = new float[width, height];
    26.         for (int x = 0; x < width; x++)
    27.         {
    28.             for (int y = 0; y < height; y++)
    29.             {
    30.                 heights[x, y] = CalculateHeight(x, y);
    31.             }
    32.         }
    33.  
    34.         return heights;
    35.     }
    36.  
    37.     float CalculateHeight (int x, int y)
    38.     {
    39.         float xCoord = x / width * scale;
    40.         float yCoord = y / height * scale;
    41.  
    42.         return Mathf.PerlinNoise(xCoord, yCoord);
    43.     }
     
    Last edited: Jan 4, 2018
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    There's no scale variable. You need to add one, either at the class level or inside the CalculateHeight method.
    :)
     
  3. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
  4. m3wtw0

    m3wtw0

    Joined:
    Jan 4, 2018
    Posts:
    2
    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?
     
  5. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Okay.. the only thing I can think of, is to literally start at the beginning if that didn't make sense to you.
    Here: https://unity3d.com/learn/tutorials/s/scripting

    Start at the very first one.. :)

    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**).