Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Water : MonoBehaviour {
- public GameObject ocean;
- bool tideRising;
- bool wavesMoving;
- Vector3 tideHighest;
- Vector3 tideLowest;
- float dayDuration;
- float outWave;
- float inWave;
- float amountRequired;
- // Use this for initialization
- void Start () {
- ocean = this.gameObject;
- tideHighest = ocean.transform.position;
- tideLowest = new Vector3(tideHighest.x, tideHighest.y - 1, tideHighest.z);
- dayDuration = 120f;
- outWave = 2f;
- inWave = 1.5f;
- amountRequired = Mathf.Floor ((dayDuration / 2) / (outWave + inWave));
- wavesMoving = false;
- }
- void tideGoesOut() {
- ocean.transform.position = Vector3.Lerp (ocean.transform.position, tideLowest, Time.deltaTime*5);
- if(ocean.transform.position.y <= tideLowest.y){
- tideRising = false;
- wavesMoving = false;
- ocean.transform.position = tideLowest;
- }
- }
- void tideComesIn() {
- ocean.transform.position = Vector3.Lerp (ocean.transform.position, tideHighest, Time.deltaTime*5);
- if (ocean.transform.position.y >= tideHighest.y) {
- tideRising = false;
- wavesMoving = false;
- ocean.transform.position = tideHighest;
- }
- }
- // Update is called once per frame
- void Update () {
- if(!wavesMoving){
- if (tideRising){
- wavesMoving = true;
- tideComesIn();
- } else {
- wavesMoving = true;
- tideGoesOut();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement