Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- //An example of overriding the time-index used by the water shader, and the Buoyancy API.
- namespace StylizedWater2.Examples
- {
- [ExecuteAlways]
- public class SetWaterTimeOffset : MonoBehaviour
- {
- public enum Mode
- {
- None,
- Interval,
- Time,
- EditorTime,
- Custom
- }
- public Mode mode = Mode.Custom;
- public float interval = 0.2f;
- public float customTime = 0f;
- private float elapsedTime;
- void Update()
- {
- if (mode == Mode.None)
- {
- OnDisable();
- return;
- }
- if (mode == Mode.Interval)
- {
- elapsedTime += Time.deltaTime;
- if (elapsedTime >= interval)
- {
- elapsedTime = 0;
- StylizedWater2.WaterObject.CustomTime = Time.time;
- }
- }
- if (mode == Mode.Time)
- {
- StylizedWater2.WaterObject.CustomTime = Time.time;
- }
- #if UNITY_EDITOR
- if (mode == Mode.EditorTime)
- {
- StylizedWater2.WaterObject.CustomTime = (float)UnityEditor.EditorApplication.timeSinceStartup;
- }
- #endif
- if (mode == Mode.Custom)
- {
- StylizedWater2.WaterObject.CustomTime = customTime;
- }
- }
- private void OnDisable()
- {
- //Revert to using normal time
- StylizedWater2.WaterObject.CustomTime = -1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement