2
0

ReduceClippingDistanceVolume.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using UnityEngine;
  3. [RequireComponent(typeof(Collider))]
  4. public class ReduceClippingDistanceVolume : MonoBehaviour
  5. {
  6. public int reducePreClippingDistanceTo = 300;
  7. public int reduceSmallObjectsDistanceTo = 100;
  8. private IgnoreClipping ignoreClipping;
  9. private bool reduced = false;
  10. private void Start()
  11. {
  12. var cam = Camera.main;
  13. if (cam == null)
  14. {
  15. Debug.LogError("No camera found!");
  16. return;
  17. }
  18. ignoreClipping = cam.GetComponent<IgnoreClipping>();
  19. if (ignoreClipping == null)
  20. {
  21. Debug.LogError("No IgnoreClipping attached to Main Camera");
  22. }
  23. }
  24. private void OnTriggerEnter(Collider other)
  25. {
  26. if (!other.CompareTag("bike") || reduced) return;
  27. ignoreClipping.applyDistances(reducePreClippingDistanceTo, reduceSmallObjectsDistanceTo);
  28. }
  29. private void OnTriggerExit(Collider other)
  30. {
  31. if (!other.CompareTag("bike") || !reduced) return;
  32. ignoreClipping.applyDistances();
  33. }
  34. }