I am trying to set the main texture of an material to a Texture2D. I am using this line of code to do it:
renderer.material.SetTexture("_MainTex", tex);
But it doesn’t work…
For some extra info:
I am using the Universal Render Pipeline.
The object I’m trying to set the texture of is a plane i have created in the code as well. Here is the code:
GameObject display = new GameObject("Display");
MeshFilter filter = display.AddComponent(typeof(MeshFilter)) as MeshFilter;
filter.mesh = planeMesh;
MeshRenderer renderer = display.AddComponent(typeof(MeshRenderer)) as MeshRenderer;
renderer.material = displayMat;
renderer.material.SetTexture("_MainTex", tex);
(The “planeMesh” and “displayMat” and “tex” are defined earlier in the script)
Can someone help me?