Question by
Novakk · Mar 22, 2021 at 01:50 AM ·
perlin noise
I was trying to set up a Perlin noise based terrain and I got 24 of the same errors.
Here is the error: The referenced script (unknown) on this Behaviour is misssing!
Here is my script:
`using UnityEngine;
public class PerlinNoise : MonoBehaviour { public int depth = 20;
public int width = 256;
public int height = 256;
public float scale = 20f;
void Start ()
{
Terrain terrain = GetComponent<Terrain>();
terrain.terrainData = GenerateTerrain(terrain.terrainData);
}
TerrainData GenerateTerrain (TerrainData terrainData)
{
terrainData.heightmapResolution = width + 1;
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 = (float)x / width * scale;
float yCoord = (float)y / height * scale;
return Mathf.PerlinNoise(xCoord, yCoord);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613031116im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do you generate a circle terrain mesh 0 Answers
Symmetrical perlin noise 1 Answer
Texture does not scale correctly on a mesh 0 Answers
Following the trail of Perlin Noise random movement? 1 Answer
Seamless Perlin Noise problem. SOLVED 0 Answers