Advertisement
Staggart

Stylized Water 2 - Set custom time

Mar 1st, 2024 (edited)
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. namespace StylizedWater2.Examples
  4. {
  5.     [ExecuteAlways]
  6.     public class SetWaterTimeOffset : MonoBehaviour
  7.     {
  8.         public enum Mode
  9.         {
  10.             None,
  11.             Interval,
  12.             Time,
  13.             EditorTime,
  14.             Custom
  15.         }
  16.  
  17.         public Mode mode = Mode.Custom;
  18.  
  19.         public float interval = 0.2f;
  20.         public float customTime = 0f;
  21.         private float elapsedTime;
  22.  
  23.         void Update()
  24.         {
  25.             if (mode == Mode.None)
  26.             {
  27.                 OnDisable();
  28.                 return;
  29.             }
  30.  
  31.             if (mode == Mode.Interval)
  32.             {
  33.                 elapsedTime += Time.deltaTime;
  34.  
  35.                 if (elapsedTime >= interval)
  36.                 {
  37.                     elapsedTime = 0;
  38.  
  39.                     StylizedWater2.WaterObject.CustomTime = Time.time;
  40.                 }
  41.             }
  42.  
  43.             if (mode == Mode.Time)
  44.             {
  45.                 StylizedWater2.WaterObject.CustomTime = Time.time;
  46.             }
  47.            
  48.             #if UNITY_EDITOR
  49.             if (mode == Mode.EditorTime)
  50.             {
  51.                 StylizedWater2.WaterObject.CustomTime = (float)UnityEditor.EditorApplication.timeSinceStartup;
  52.             }
  53.             #endif
  54.  
  55.             if (mode == Mode.Custom)
  56.             {
  57.                 StylizedWater2.WaterObject.CustomTime = customTime;
  58.             }
  59.         }
  60.  
  61.         private void OnDisable()
  62.         {
  63.             //Revert to using normal time
  64.             StylizedWater2.WaterObject.CustomTime = -1;
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement