why does my script not work even though I followed a tutorial?
I followed a Sebastian Lague tutorial about procedural generation but even though I copied his code letter by letter (I think) it doesn't work! Maybe it's because his tutorial is from six years ago but still, the components shouldn't have changed so much so that his code won't work! Someone please tell me where I went wrong. https://www.youtube.com/watch?v=WP-Bm65Q-1Y This is my code:
using UnityEngine;
public class MapDisplay : MonoBehaviour
{
public RenderBuffer textureRender;
public void DrawNoiseMap(float[,] noiseMap)
{
int width = noiseMap.GetLength(0);
int height = noiseMap.GetLength(1);
Texture2D texture = new Texture2D(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();
Texture2D texture1 = texture;
textureRender.sharedMaterials.mainTexture = texture1;
textureRender.transform.localSCale = new Vector3(width, 1, height);
}
}
It keeps saying that 'RenderBuffer' does not contain a definition for 'sharedMaterial' and no accessible extension method 'sharedMaterials' accepting a first argument of type 'RenderBuffer' could be found (are you missing a using directive or an assembly reference?) it says this about transform as well. In case this has something to do with some of my other code, here's all my code:
using UnityEngine;
public class MapGenerator : MonoBehaviour
{
public int mapWidth;
public int mapHeight;
public float noiseScale;
public void GenerateMap()
{
float[,] noiseMap = Noise.GenerateNoiseMap(mapWidth, mapHeight, noiseScale);
MapDisplay display = FindObjectOfType<MapDisplay>();
display.DrawNoiseMap(noiseMap);
}
}
.
using UnityEditor;
using UnityEngine;
public class MapGeneratorEditor : Editor
{
public override void OnInspectorGUI()
{
MapGenerator mapGen = (MapGenerator)target;
DrawDefaultInspector();
if (GUILayout.Button("Generate"))
{
mapGen.GenerateMap();
}
}
}
If someone figures out how I went wrong, please tell me how to fix it! :)