Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

var mesh: Mesh;

Description

Returns the instantiated Mesh assigned to the mesh filter.

If no mesh is assigned to the mesh filter a new mesh will be created and assigned.

If a mesh is assigned to the mesh filter already, then first query of mesh property will create a duplicate of it, and this copy will be returned. Further queries of mesh property will return this duplicated mesh instance. If you want to avoid this automatic mesh duplication, use MeshFilter.sharedMesh instead.

By using mesh property you can modify the mesh for a single object only. The other objects that used the same mesh will not be modified.

	// Distortionates the mesh vertically.

function Update () { // Get instantiated mesh var mesh : Mesh = GetComponent(MeshFilter).mesh; // Randomly change vertices var vertices : Vector3[] = mesh.vertices; for (var p : int = 0; p < vertices.Length; p++) { vertices[p] += Vector3(0, Random.Range(-0.3, 0.3), 0); } mesh.vertices = vertices; mesh.RecalculateNormals(); }

See Also: Mesh class.