[Unity Combat] make a scrolling wave

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.