1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
-
- using UnityEngine;
- using System.Collections;
- public class WaterWave : MonoBehaviour {
-
- public float scale = 0.5f;
- public float speed = 1f;
- public bool isMultiply = false;//若为true则波浪数变多
-
- private Mesh mesh;
- private Vector3[] baseVertex;
- private Vector3[] nowVertex;
-
- // Use this for initialization
- void Start ()
- {
- mesh = GetComponent<MeshFilter>().mesh;
- baseVertex = mesh.vertices;
- nowVertex = mesh.vertices;
- }
-
- // Update is called once per frame
- void 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;
- }
- }
|