C# 为什么要画一个三角形I';我在uv';s
它画了一个三角形,但也有例外C# 为什么要画一个三角形I';我在uv';s,c#,unity3d,C#,Unity3d,它画了一个三角形,但也有例外 using System.Collections; using System.Collections.Generic; using UnityEngine; public class MeshGenerator : MonoBehaviour { public GameObject meshPrefab; public Vector3[] newVertices; public Vector2[] newUV; public int
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MeshGenerator : MonoBehaviour
{
public GameObject meshPrefab;
public Vector3[] newVertices;
public Vector2[] newUV;
public int[] newTriangles;
private Mesh mesh;
void Start()
{
Mesh meshprefab = meshPrefab.GetComponent<MeshFilter>().sharedMesh;
newVertices = meshprefab.vertices;
newUV = meshprefab.uv;
newTriangles = meshprefab.triangles;
mesh = new Mesh();
mesh = gameObject.GetComponent<MeshFilter>().mesh;
mesh.Clear();
mesh.uv = new Vector2[] { new Vector2(0, 0), new Vector2(0, 0.25f), new Vector2(0.25f, 0.25f) };
mesh.vertices = new Vector3[] { new Vector3(0, 0, 0), new Vector3(0, 0.25f, 0), new Vector3(0.25f, 0.25f, 0) };
mesh.triangles = new int[] { 0, 1, 2 };
}
}
Mesh.uv已超出范围。提供的数组需要与Mesh.vertices数组的大小相同。
UnityEngine.Mesh:set_uv(Vector2[])您需要将顶点数组赋值语句移动到uv语句之前,因为Unity当前认为顶点数为零
mesh.vertices = ...
mesh.uv = ...
mesh.vertices = ...
mesh.uv = ...