Advertisement
Cookie042

ref

Jul 13th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. [ExecuteAlways, RequireComponent(typeof(ReflectionProbe))]
  4. public class RealtimeReflection : MonoBehaviour
  5. {
  6.     public Transform target; // camera
  7.     public Transform groundPlane;
  8.  
  9.     public ReflectionProbe probe;
  10.  
  11.     private Vector3 initialPosition;
  12.     private Vector3 initialOffset;
  13.    
  14.     private void OnEnable()
  15.     {
  16.         probe = GetComponent<ReflectionProbe>();
  17.  
  18.         initialPosition = transform.position;
  19.         initialOffset = probe.center;
  20.     }
  21.  
  22.     private void OnDisable()
  23.     {
  24.         transform.position = initialPosition;
  25.         probe.center = initialOffset;
  26.     }
  27.    
  28.     // Update is called once per frame
  29.     void Update()
  30.     {
  31.         if (!target || !groundPlane) return;
  32.        
  33.         var cameraHeight = Vector3.Dot(target.transform.position - groundPlane.position, groundPlane.up);
  34.         var undergroudnPosition = target.transform.position - cameraHeight * 2 * groundPlane.up;
  35.  
  36.         probe.transform.position = undergroudnPosition;
  37.         probe.center = initialPosition - undergroudnPosition;
  38.  
  39.         probe.RenderProbe();
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement