Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Water : MonoBehaviour {
  5.  
  6.     public GameObject ocean;
  7.     bool tideRising;
  8.     bool wavesMoving;
  9.     Vector3 tideHighest;
  10.     Vector3 tideLowest;
  11.     float dayDuration;
  12.     float outWave;
  13.     float inWave;
  14.     float amountRequired;
  15.  
  16.     // Use this for initialization
  17.     void Start () {
  18.         ocean = this.gameObject;
  19.         tideHighest = ocean.transform.position;
  20.         tideLowest = new Vector3(tideHighest.x, tideHighest.y - 1, tideHighest.z);
  21.         dayDuration = 120f;
  22.         outWave = 2f;
  23.         inWave = 1.5f;
  24.         amountRequired = Mathf.Floor ((dayDuration / 2) / (outWave + inWave));
  25.         wavesMoving = false;
  26.     }
  27.  
  28.  
  29.  
  30.     void tideGoesOut() {
  31.         ocean.transform.position = Vector3.Lerp (ocean.transform.position, tideLowest, Time.deltaTime*5);
  32.         if(ocean.transform.position.y <= tideLowest.y){
  33.             tideRising = false;
  34.             wavesMoving = false;
  35.             ocean.transform.position = tideLowest;
  36.         }
  37.     }
  38.  
  39.     void tideComesIn() {
  40.         ocean.transform.position = Vector3.Lerp (ocean.transform.position, tideHighest, Time.deltaTime*5);
  41.         if (ocean.transform.position.y >= tideHighest.y) {
  42.             tideRising = false;
  43.             wavesMoving = false;
  44.             ocean.transform.position = tideHighest;
  45.         }
  46.     }
  47.    
  48.     // Update is called once per frame
  49.     void Update () {
  50.         if(!wavesMoving){
  51.             if (tideRising){
  52.                 wavesMoving = true;
  53.                 tideComesIn();
  54.             } else {
  55.                 wavesMoving = true;
  56.                 tideGoesOut();
  57.             }
  58.         }  
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement