Version: 2020.1
public Vector3[] vertices ;

描述

返回顶点位置的副本或分配新顶点位置数组。

网格中的顶点数可通过分配具有不同顶点数的顶点数组来更改。 请注意,如果调整顶点数组大小,则所有其他顶点属性(法线、颜色、切线、UV)也会自动调整大小。 如果在设置顶点时尚未向网格分配顶点,则会自动调用 RecalculateBounds

using UnityEngine;

public class Example : MonoBehaviour { Mesh mesh; Vector3[] vertices; void Start() { mesh = GetComponent<MeshFilter>().mesh; vertices = mesh.vertices; }

void Update() { for (var i = 0; i < vertices.Length; i++) { vertices[i] += Vector3.up * Time.deltaTime; }

// assign the local vertices array into the vertices array of the Mesh. mesh.vertices = vertices; mesh.RecalculateBounds(); } }

注意:若要对 vertices 进行更改,从 Mesh 复制 顶点十分重要。复制和更改 vertices 之后,vertices 即可重新分配回 Mesh