Created
September 29, 2015 04:42
-
-
Save davepape/e9019805374b88231d44 to your computer and use it in GitHub Desktop.
modifying a GameObject's geometry data (mesh) in Unity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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