using UnityEngine;

public class Water : MonoBehaviour {

    [SerializeField] private float scale = 7.0f;
    [SerializeField] private float heightScale = 1.0f;
    [SerializeField] private int fps = 60;

    private MeshFilter mf = null;

    void Start() {
        mf = GetComponent<MeshFilter>();
        if (mf == null) {
            Debug.LogError("Error : There must be a Skybox component on this GameObject !");
            return;
        } else {
            InvokeRepeating("RandomHeight", 0, 1f / fps);
        }
    }

    void RandomHeight() {
        Vector3[] vertices = mf.mesh.vertices;
        for (int i = 0; i < vertices.Length; i++) {
            vertices[i].y = heightScale * Mathf.PerlinNoise(Time.time + (vertices[i].x * scale), Time.time + (vertices[i].z * scale));
        }
        mf.mesh.vertices = vertices;
    }
}