/MeshTestBend.cs Secret
Last active
August 9, 2018 03:46
This file contains 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
using UnityEngine; | |
public class MeshTestBend : MonoBehaviour | |
{ | |
// We will get 2 copies of vertices, | |
// so that we could use the original positions as an input | |
Vector3[] vertices; | |
Vector3[] originalVertices; | |
// Reference to the mesh | |
Mesh mesh; | |
void Start() | |
{ | |
var meshFilter = gameObject.GetComponent<MeshFilter>(); | |
mesh = meshFilter.sharedMesh; | |
// get 2 copies of vertices from an existing mesh | |
vertices = mesh.vertices; | |
originalVertices = mesh.vertices; | |
} | |
void Update() | |
{ | |
for (int i = 0; i < vertices.Length; i++) | |
{ | |
// Move vertices in a sine wave according to their starting positions and time | |
vertices[i].y = originalVertices[i].y + Mathf.Sin(originalVertices[i].z + Time.time); | |
} | |
// Assign vertices to mesh | |
mesh.vertices = vertices; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment