19 lines
691 B
C#
19 lines
691 B
C#
using UnityEngine;
|
|
|
|
namespace Movement
|
|
{
|
|
public class CollisionChecker : MonoBehaviour
|
|
{
|
|
private Collider2D[] nonAllocColliderArray = new Collider2D[5]; // TODO increase the size if it causes problems
|
|
|
|
public LayerMask layerMask = ~((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);
|
|
}
|
|
}
|
|
}
|