Я учусь создавать сетки по коду в Unity, но текстура странная, как на картинке, кто-нибудь знает, почему это так? Я создал UV-карту, как она есть в коде, много искал в документации Google и Unity и увидел, что мне нужно использовать вершины массива для отображения UV, но я думаю, что сделал что-то не так
Мой код:
public Vector3[] verts = {
new Vector3(-0.5f, 0.5f, 0f), new Vector3(0.5f, 0.5f, 0f),
new Vector3(0.5f, -0.5f, 0f), new Vector3(-0.5f, -0.5f, 0f),
new Vector3(-0.2f, 0.3f, 0f), new Vector3(0.2f, 0.3f, 0f),
new Vector3(0.2f, -0.1f, 0f), new Vector3(-0.2f, -0.1f, 0f),
new Vector3(-0.2f, 0.3f, 0f), new Vector3(0.2f, 0.3f, 0f),
new Vector3(0.2f, -0.1f, 0f), new Vector3(-0.2f, -0.1f, 0f),
new Vector3(-0.2f, 0.3f, 0.1f), new Vector3(0.2f, 0.3f, 0.1f),
new Vector3(0.2f, -0.1f, 0.1f), new Vector3(-0.2f, -0.1f, 0.1f),
new Vector3(-0.2f, 0.3f, 0.1f), new Vector3(0.2f, 0.3f, 0.1f),
new Vector3(0.2f, -0.1f, 0.1f), new Vector3(-0.2f, -0.1f, 0.1f),
new Vector3(-0.5f, 0.5f, 0.1f), new Vector3(-0.5f, -0.5f, 0.1f),
new Vector3(-0.5f, -0.5f, 0.1f), new Vector3(-0.5f, -0.5f, 0.1f),
new Vector3(-0.5f, -0.5f, 0.1f), new Vector3(-0.5f, -0.5f, 0.1f),
new Vector3(-0.5f, -0.5f, 0.1f), new Vector3(-0.5f, -0.5f, 0.1f),
new Vector3(-0.5f, -0.5f, 0.1f), new Vector3(-0.5f, -0.5f, 0.1f),
new Vector3(-0.5f, -0.5f, 0.1f), new Vector3(-0.5f, -0.5f, 0.1f),
new Vector3(-0.5f, -0.5f, 0.1f), new Vector3(-0.5f, -0.5f, 0.1f),
new Vector3(-0.5f, -0.5f, 0.1f), new Vector3(-0.5f, -0.5f, 0.1f),
new Vector3(-0.5f, -0.5f, 0.1f), new Vector3(-0.5f, -0.5f, 0.1f),
new Vector3(-0.5f, -0.5f, 0.1f), new Vector3(-0.5f, -0.5f, 0.1f),
new Vector3(-0.5f, -0.5f, 0.1f), new Vector3(-0.5f, -0.5f, 0.1f),
new Vector3(-0.5f, -0.5f, 0.1f), new Vector3(-0.5f, -0.5f, 0.1f),
new Vector3(-0.5f, -0.5f, 0.1f), new Vector3(-0.5f, -0.5f, 0.1f),
new Vector3(0.5f, 0.5f, 0.1f), new Vector3(0.5f, -0.5f, 0.1f)
};
public int[] tris = {
0,1,4,1,5,4,1,2,5,2,6,5,2,3,6,3,7,6,3,0,7,0,4,7,8,9,12,9,13,12,9,10,13,10,14,13,10,11,14,11,15,14,11,8,15,8,12,15,20,0,3,20,3,21,0,20,46,0,46,1,1,46,47,1,47,2,3,2,42,2,47,45,46,20,17,20,16,17,20,19,16,20,32,15,31,14,15,31,47,14,47,46,14,46,17,14
};
MeshFilter mF = gameObject.GetComponent<MeshFilter> ();
Mesh msh = new Mesh ();
msh.vertices = verts;
msh.triangles = tris;
Vector2[] uvs = new Vector2[verts.Length];
for (int i = 0; i < uvs.Length; i++){ //uv map
uvs[i] = new Vector2(verts[i].x, verts[i].y);
}
msh.uv = uvs;
msh.RecalculateNormals ();
mF.mesh = msh;