Skip to content

Instantly share code, notes, and snippets.

@nothke
Last active August 9, 2018 03:46
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