Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- [ExecuteAlways, RequireComponent(typeof(ReflectionProbe))]
- public class RealtimeReflection : MonoBehaviour
- {
- public Transform target; // camera
- public Transform groundPlane;
- public ReflectionProbe probe;
- private Vector3 initialPosition;
- private Vector3 initialOffset;
- private void OnEnable()
- {
- probe = GetComponent<ReflectionProbe>();
- initialPosition = transform.position;
- initialOffset = probe.center;
- }
- private void OnDisable()
- {
- transform.position = initialPosition;
- probe.center = initialOffset;
- }
- // Update is called once per frame
- void Update()
- {
- if (!target || !groundPlane) return;
- var cameraHeight = Vector3.Dot(target.transform.position - groundPlane.position, groundPlane.up);
- var undergroudnPosition = target.transform.position - cameraHeight * 2 * groundPlane.up;
- probe.transform.position = undergroudnPosition;
- probe.center = initialPosition - undergroudnPosition;
- probe.RenderProbe();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement