Skip to content

Instantly share code, notes, and snippets.

@davepape
Created September 29, 2015 04:42
Show Gist options
  • Select an option

  • Save davepape/e9019805374b88231d44 to your computer and use it in GitHub Desktop.

Select an option

Save davepape/e9019805374b88231d44 to your computer and use it in GitHub Desktop.
modifying a GameObject's geometry data (mesh) in Unity
#pragma strict
// Script to warp an existing mesh.
// This can be attached to any GameObject that includes a Mesh Filter.
// It will move the vertices up and down in Y, based on the sine of the X
// value + the time.
private var originalVerts : Vector3[];
function Start ()
{
var m = GetComponent.<MeshFilter>().mesh;
originalVerts = m.vertices;
}
function Update()
{
var m = GetComponent.<MeshFilter>().mesh;
var verts = m.vertices;
for (var i=0; i < verts.Length; i++)
{
verts[i] = originalVerts[i] + Vector3(0,Mathf.Sin(originalVerts[i][0]*3+Time.time)/4.0, 0);
}
m.vertices = verts;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment