UnityBiz/Assets/scripts/Movement/GroundChecker.cs
adamwi1000 b854205dcb test
2024-08-02 06:41:41 +02:00

31 lines
904 B
C#

using UnityEngine;
namespace Player.Movement
{
public class GroundChecker
{
public Transform Transform { get; private set; }
public Bounds Bounds { get; private set; }
public float ExtraHeight { get; private set; }
public RaycastHit RaycastHit { get; private set; }
public bool IsObjectGrounded { get; private set; }
public bool IsGrounded(Transform transform, Bounds bounds, float extraHeight, out RaycastHit[] hit, int layerMask)
{
hit = new RaycastHit[5];
var hits = Physics.BoxCastNonAlloc(bounds.center,
bounds.extents / 2,
Vector3.down,
hit,
transform.rotation,
bounds.extents.y / 2 + extraHeight,
layerMask);
IsObjectGrounded = hits > 0;
return IsObjectGrounded;
}
}
}