using System.Collections; using System.Collections.Generic; using UnityEngine; public class MapDisplay : MonoBehaviour { [SerializeField] Renderer _textureRenderer; public void DrawNoiseMap(float[,] noiseMap) { int width = noiseMap.GetLength(0); int height = noiseMap.GetLength(1); Texture2D texture = new Texture2D(width, height); // do this beacuse set pixels is faster than set pixels singly Color[] colourMap = new Color[width * height]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { //we can get first index by first multiplying Y by the width of the map beacuse colourMap is 1-dimensional board and noiseMap is 2-dimensionals 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); } }