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;
- Vector3 tideHighest;
- Vector3 tideLowest;
- float dayDuration;
- float outWave;
- float inWave;
- float amountRequired;
- private float startTime;
- private float journeyLength;
- // 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));
- tideRising = false;
- startTime = Time.time;
- journeyLength = Vector3.Distance(ocean.transform.position, tideLowest);
- }
- void tideGoesOut() {
- float distCovered = (Time.time - startTime) * outWave;
- float fracJourney = distCovered / journeyLength;
- ocean.transform.position = Vector3.Lerp (ocean.transform.position, tideLowest, fracJourney);
- if(ocean.transform.position.y <= tideLowest.y){
- tideRising = true;
- startTime = Time.time;
- journeyLength = Vector3.Distance(ocean.transform.position, tideHighest);
- //ocean.transform.position = tideLowest;
- }
- }
- void tideComesIn() {
- float distCovered = (Time.time - startTime) * inWave;
- float fracJourney = distCovered / journeyLength;
- ocean.transform.position = Vector3.Lerp (ocean.transform.position, tideHighest, fracJourney);
- if (ocean.transform.position.y >= tideHighest.y) {
- tideRising = false;
- startTime = Time.time;
- journeyLength = Vector3.Distance(ocean.transform.position, tideLowest);
- //ocean.transform.position = tideHighest;
- }
- }
- // Update is called once per frame
- void Update () {
- if (tideRising){
- tideComesIn();
- } else {
- tideGoesOut();
- }
- Debug.Log ("Highest: " + tideHighest);
- Debug.Log ("Lowest: " + tideLowest);
- Debug.Log ("Current Position: " + ocean.transform.position);
- Debug.Log (tideRising);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement