我在Unity中有一个预制立方体。我已经运行了一些脚本来定位它,并移动一些顶点来改变它的形状。现在,我知道要纹理它,我必须做类似的事情:
Texture2D myTexture = Resources.Load("sample") as Texture2D;
cube.GetComponent<Renderer>().material.mainTexture = (Texture)myTexture;
这非常有效。但现在,我想了解如何使用UV贴图为我的立方体分配2个不同的纹理(1个用于顶部,1个用于侧面)。
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;
答案 0 :(得分:0)
您的“顶点”和“UV”匹配,以便“顶点”数组中的每个位置对应于相同位置的UV矢量。
vertices[0] // will map to...
uvs[0]
您的顶点描述了多维数据集中的每个顶点。然后你基本上将纹理的点固定到它。请记住,您的纹理坐标是最小值和最大值为0和1。