- Home /
Texturing 1 side of a cube using C# script
So, I have a prefab cube in Unity. I already run some script to position it, and move some of the vertices to change it's shape. Now, I know that to texture it, I have to do something like:
Texture2D myTexture = Resources.Load("sample") as Texture2D;
cube.GetComponent<Renderer>().material.mainTexture = (Texture)myTexture;
And that works very well. But now, I want to understand how to use UV mapping to assign 2 different texture to my cube (1 for top and 1 for side).
Texture2D topTexture = Resources.Load("topTex") as Texture2D;
Texture2D sideTexture = Resources.Load("sideTex") as Texture2D;
//And now, how do I say to only apply to which side?
cube.GetComponent<Renderer>().material.mainTexture = (Texture)topTexture;
cube.GetComponent<Renderer>().material.mainTexture = (Texture)sideTexture;
THANK YOU!!!
Comment
Your answer
Follow this Question
Related Questions
Assigning script-generated textures 0 Answers
Scroll using material.mainTextureOffset makes the texture very distorted 1 Answer
Distribute terrain in zones 3 Answers
Blend 2 Textures Unity C# 0 Answers
Applying a texture to a cube appropriate direction 0 Answers