uurha

Untitled

Aug 2nd, 2021
710
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class DistanceValidator : MonoBehaviour
  2. {
  3.     [SerializeField] private Transform plane;
  4.     [SerializeField] private float closeDistance;
  5.    
  6.     private void OnDrawGizmos()
  7.     {
  8.         var position = transform.position;
  9.         var transformPoint = plane.TransformPoint(Vector3.ProjectOnPlane(position, plane.up));
  10.         var distance = Vector3.Distance(position, transformPoint);
  11.  
  12.         if (distance <= closeDistance)
  13.         {
  14.             Gizmos.color = Color.red;
  15.         }
  16.         else
  17.         {
  18.             Gizmos.color = Color.white;
  19.         }
  20.        
  21.         Gizmos.DrawLine(position, transformPoint);
  22.        
  23.     }
  24.  
  25. }
RAW Paste Data