2022-02-21 16:27:23 +03:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace Movement
|
|
|
|
{
|
2022-02-21 19:09:59 +03:00
|
|
|
public class CollisionChecker : MonoBehaviour
|
2022-02-21 16:27:23 +03:00
|
|
|
{
|
2022-02-21 19:30:46 +03:00
|
|
|
private Collider2D[] nonAllocColliderArray = new Collider2D[5]; // TODO increase the size if it causes problems
|
2022-02-21 16:27:23 +03:00
|
|
|
|
2022-02-21 20:43:25 +03:00
|
|
|
public LayerMask layerMask = ~((1 << 6) | (1 << 7)); // Everything except the "Player" and "Enemy" layer
|
2022-02-21 20:43:47 +03:00
|
|
|
public bool IsCollided => Physics2D.OverlapBoxNonAlloc(transform.position, transform.localScale, 0, nonAllocColliderArray, layerMask) != 0;
|
2022-02-21 16:27:23 +03:00
|
|
|
|
|
|
|
public void OnDrawGizmosSelected()
|
|
|
|
{
|
|
|
|
Gizmos.color = IsCollided ? Color.green : Color.red;
|
|
|
|
Gizmos.DrawWireCube(transform.position, transform.localScale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|