Version: 2020.2
public Mesh sharedMesh ;

描述

返回网格过滤器的共享网格。

建议仅将此函数用于读取网格数据 而不用于写入,因为您可能会修改导入的资源,使用此网格 的所有对象都会受影响。 此外请注意,无法撤销对此网格进行的更改。

using UnityEngine;

public class Example : MonoBehaviour { // Permanently scales the size of the mesh by a factor.

float scaleFactor = 2f;

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

Vector3[] vertices = mesh.vertices; for (int p = 0; p < vertices.Length; p++) { vertices[p] *= scaleFactor; } mesh.vertices = vertices; mesh.RecalculateNormals(); } }