반응형
- 코드 작성
using UnityEngine;
public class AutoTerrainExample : MonoBehaviour
{
[SerializeField] private TerrainData terrainData;
[SerializeField] private int resolution = 256;
[SerializeField] private float scale = 10f;
[SerializeField] private float heightScale = 5f;
private void Start()
{
terrainData.heightmapResolution = resolution;
terrainData.size = new Vector3(resolution, heightScale, resolution);
float[,] heights = new float[resolution, resolution];
for (int x = 0; x < resolution; x++)
{
for (int y = 0; y < resolution; y++)
{
float perlin = Mathf.PerlinNoise((float)x / resolution * scale, (float)y / resolution * scale);
heights[x, y] = perlin * heightScale;
}
}
terrainData.SetHeights(0, 0, heights);
}
}
반응형