Answers for "how to assign a texture to a Meshrenderer unity"

C#
1

how to assign a texture to a Meshrenderer unity

// Initialize a 2D texture of sizeX by sizeY
Texture2D texture = new Texture2D(sizeX, sizeY);

// Set the colors to it (an array of colors), 
// but you can also use texture.SetPixel(x, y, color) to set
// the pixel at (x, y) coordinates to the color 'color'
texture.SetPixels(colors);
// DON'T FORGET TO APPLY THE TEXTURE (VERY IMPORTANT)
texture.Apply();

// Set it to your MeshRender
meshRenderer.sharedMaterial.mainTexture = texture;
Posted by: Guest on January-16-2021

Code answers related to "how to assign a texture to a Meshrenderer unity"

C# Answers by Framework

Browse Popular Code Answers by Language