35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
|
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 (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);
|
||
|
return vector3.y == collider.bounds.center.y + collider.bounds.extents.y;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
}
|