| 1234567891011121314151617181920212223242526272829 |
- using UnityEngine;
- public class MapDisplay : MonoBehaviour
- {
- public Renderer textureRenderer;
- public void DrawNoiseMap(float[,] noiseMap)
- {
- int width = noiseMap.GetLength(0);
- int height = noiseMap.GetLength(1);
- Texture2D texture = new(width, height);
- Color[] colourMap = new Color[width * height];
- for (int y = 0; y < height; y++)
- {
- for (int x = 0; x < width; x++)
- {
- colourMap[y * width + x] = Color.Lerp(Color.black, Color.white, noiseMap[x, y]);
- }
- }
- texture.SetPixels(colourMap);
- texture.Apply();
- textureRenderer.sharedMaterial.mainTexture = texture;
- textureRenderer.transform.localScale = new Vector3(width, 1, height);
- }
- }
|