Trigger/Box2DColliderTrigger.cs

25 lines
749 B
C#
Raw Normal View History

2022-11-14 12:15:32 +03:00
using UnityEngine;
namespace Syntriax.Modules.Trigger
{
public class Box2DColliderTrigger : Trigger, IColliderTrigger
{
public LayerMask ColliderMask { get => colliderMask; set => colliderMask = value; }
[SerializeField] private LayerMask colliderMask = 0;
2022-11-14 14:28:00 +03:00
private Collider2D[] results = new Collider2D[8];
2022-11-14 12:15:32 +03:00
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
}
}