using System.Collections; using System.Collections.Generic; using UnityEngine; namespace BITKit { public interface IClosePoint { bool TryGetClosePoint(out Vector3 vector3); } [System.Serializable] public class GetClosePointFromCollider : IClosePoint { public Transform root; public LayerMask layerMask; public float distance; public bool TryGetClosePoint(out Vector3 vector3) { vector3 = default; if (UnityEngine.Physics.Raycast(root.position, root.forward, out var raycastHit, distance, layerMask)) { var collider = raycastHit.collider; switch (collider) { case MeshCollider meshCollider: if (meshCollider.convex is false) return false; break; } vector3 = collider.ClosestPoint(root.position + Vector3.up); var top = collider.bounds.center + collider.bounds.extents; return Mathf.Abs(vector3.y - top.y) <0.16f; //return vector3.y >= collider.bounds.center.y + collider.bounds.extents.y; //return true; } return false; } } }