Movement/ColliderCheck/Box2DColliderTrigger.cs

26 lines
767 B
C#

using UnityEngine;
namespace Syntriax.Modules.Movement.ColliderTrigger
{
public class Box2DColliderTrigger : Trigger, IColliderTrigger
{
private Collider2D[] results = new Collider2D[8];
public LayerMask ColliderMask { get => colliderMask; set => colliderMask = value; }
[SerializeField] private LayerMask colliderMask = 0;
protected void FixedUpdate()
=> IsTrigerred = Physics2D.OverlapBoxNonAlloc(transform.position, transform.localScale, 0, results, ColliderMask) > 0;
#if UNITY_EDITOR
private void OnDrawGizmosSelected()
{
Gizmos.color = IsTrigerred ? Color.green : Color.red;
Gizmos.DrawWireCube(transform.position, transform.lossyScale);
}
#endif
}
}