mesh error -

here's the error messages

Mesh.vertices is too small. The supplied vertex array has less vertices than are referenced by the triangles array.
Mesh.normals is out of bounds. The supplied array needs to be the same size as the Mesh.vertices array.
Mesh.uv is out of bounds. The supplied array needs to be the same size as the Mesh.vertices array.

  Continously changing the mesh triangles and vertices:
a) call Clear to start fresh
b) assign vertices and other attributes
c) assign triangle indices.

It is important to call Clear before assigning new vertices or triangles. Unity always checks the supplied triangle indices whether they don't reference out of bounds vertices. Calling Clear then assigning vertices then triangles makes sure you never have out of bounds data.

using UnityEngine;

public class ExampleClass : MonoBehaviour { Vector3[] newVertices; Vector2[] newUV; int[] newTriangles;

void Start() { Mesh mesh = GetComponent<MeshFilter>().mesh;

mesh.Clear();

// Do some calculations... mesh.vertices = newVertices; mesh.uv = newUV; mesh.triangles = newTriangles; } }
posted @ 2017-11-24 10:59  何人之名  阅读(1289)  评论(1)    收藏  举报