BGJ-2022.1/Assets/Scripts/Movement/CollisionChecker.cs

19 lines
657 B
C#

using UnityEngine;
namespace Movement
{
public class CollisionChecker : MonoBehaviour
{
private Collider2D[] nonAllocColliderArray = new Collider2D[5];
public LayerMask LayerMask { get; set; } = ~((1 << 6) | (1 << 7)); // Everything except the "Player" and "Enemy" layer
public bool IsCollided => Physics2D.OverlapBoxNonAlloc(transform.position, transform.localScale, 0, nonAllocColliderArray, LayerMask) != 0;
public void OnDrawGizmosSelected()
{
Gizmos.color = IsCollided ? Color.green : Color.red;
Gizmos.DrawWireCube(transform.position, transform.localScale);
}
}
}