Reference Link: http://tieba.baidu.com/p/2655013091#40457365538l
:
Here, the waves we make are implemented by changing the vertices on the mesh. More accurately, the Y-value of vertices on the mesh is changed to create a highly variable effect.
1. By observing, we find that the Y value of each vertex changes differently, so it is easy to think of associating the Y value of the vertex with the x,z value of the vertex.
2. Through observation, we find that the number of waves in the first figure is small, the number of waves in the second figure is more, the smaller the wave number indicates that the Y values of each vertex are different. You can increase the difference between different vertices by enlarging the x,z value.
Using unityengine;using System.collections;public class Waterwave:monobehaviour {public float scale = 0.5f; public float speed = 1f; public bool ismultiply = false;//If True, the number of waves becomes more private mesh mesh; Private vector3[] Basevertex; Private vector3[] nowvertex;//use this for initializationvoid Start () {mesh = getcomponent<meshfilter> (). Mesh; Basevertex = mesh.vertices; Nowvertex = mesh.vertices;} Update is called once per framevoid update () {for (int i = 0; i < basevertex.length; i++) { Nowvertex[i] = Basevertex[i]; if (ismultiply) {nowvertex[i].y + = Mathf.sin (Time.time * speed + basevertex[i].x + basevertex[i ].Z) * scale; } else {nowvertex[i].y + = Mathf.sin (Time.time * speed + basevertex[i].x) * scale + Mathf.sin (Time.time * speed + basevertex[i].z) * scale; } } Mesh.vertices = Nowvertex;}}
[Unity Combat] make a scrolling wave