1
0

MapDisplay.cs 789 B

1234567891011121314151617181920212223242526272829
  1. using UnityEngine;
  2. public class MapDisplay : MonoBehaviour
  3. {
  4. public Renderer textureRenderer;
  5. public void DrawNoiseMap(float[,] noiseMap)
  6. {
  7. int width = noiseMap.GetLength(0);
  8. int height = noiseMap.GetLength(1);
  9. Texture2D texture = new(width, height);
  10. Color[] colourMap = new Color[width * height];
  11. for (int y = 0; y < height; y++)
  12. {
  13. for (int x = 0; x < width; x++)
  14. {
  15. colourMap[y * width + x] = Color.Lerp(Color.black, Color.white, noiseMap[x, y]);
  16. }
  17. }
  18. texture.SetPixels(colourMap);
  19. texture.Apply();
  20. textureRenderer.sharedMaterial.mainTexture = texture;
  21. textureRenderer.transform.localScale = new Vector3(width, 1, height);
  22. }
  23. }