IsPointWithinCollider.cs 615 B

12345678910111213141516171819202122
  1. using UnityEngine;
  2. namespace Rokid.UXR.Interaction
  3. {
  4. public static partial class Collisions
  5. {
  6. public static bool IsPointWithinCollider(Vector3 point, Collider collider)
  7. {
  8. if (!collider.bounds.Contains(point))
  9. {
  10. return false;
  11. }
  12. Vector3 closestPoint = collider.ClosestPoint(point);
  13. if (collider is MeshCollider)
  14. {
  15. return (closestPoint - point).sqrMagnitude < collider.contactOffset * collider.contactOffset;
  16. }
  17. return closestPoint.Equals(point);
  18. }
  19. }
  20. }