Advertisement
Staggart

Stylized Water 2 - Set Water Offset

Jan 6th, 2025 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using System;
  2. using UnityEngine;
  3.  
  4. namespace StylizedWater2.Examples
  5. {
  6.     [ExecuteAlways]
  7.     public class SetWaterPositionOffset : MonoBehaviour
  8.     {
  9.         public bool negate;
  10.  
  11.         private void Update()
  12.         {
  13.             //Note: in a floating origin system, apply the value after offsetting all the transforms!
  14.             //Otherwise the water geometry gets shifted in one frame, and this offset is applied the next. This induces a jitter.
  15.             StylizedWater2.WaterObject.PositionOffset = negate ? -this.transform.position : this.transform.position;
  16.         }
  17.  
  18.         private void OnDisable()
  19.         {
  20.             StylizedWater2.WaterObject.PositionOffset = Vector3.zero;
  21.         }
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement