I am trying to use Mathf.perlinnoise to randomly create terrain for my game, but whenever I call terrainData.SetHeights unity just freezes and stops responding. I looked around but didn’t find anyone else encountering this problem. Is there something obvious I am overlooking in my code? I am using unity 4.0.0f7
void generateMap(int seed, int perlinwidthperpixel) {
Random.seed = seed;
float[,] heights = new float[(int)terrain.terrainData.heightmapWidth, (int)terrain.terrainData.heightmapHeight];
Debug.Log(terrain.terrainData.heightmapWidth);
Debug.Log(terrain.terrainData.heightmapHeight);
for (int i = 0 ; i < terrain.terrainData.heightmapWidth ; i++) {
for (int k = 0 ; k < terrain.terrainData.heightmapHeight ; k++) {
float perlin = Mathf.PerlinNoise(i*perlinwidthperpixel,k*perlinwidthperpixel);
heights[i,k] = perlin;
}
}
terrain.terrainData.SetHeights(0,0,heights);
}