Movement/ColliderCheck/TwoDimensionalBoxChildColli...

25 lines
792 B
C#
Raw Normal View History

2021-12-23 12:41:01 +03:00
using UnityEngine;
namespace Syntriax.Modules.Movement.ColliderCheck
{
public class TwoDimensionalBoxChildColliderCheck : MonoBehaviour, IColliderCheck, IState
{
[SerializeField] private LayerMask colliderMask = 0;
public LayerMask ColliderMask { get => colliderMask; set => colliderMask = value; }
public bool IsColliderDetected
=> StateEnabled ? Physics2D.OverlapBox(transform.position, transform.localScale, 0, ColliderMask) != null : true;
public bool StateEnabled { get; set; } = true;
#if UNITY_EDITOR
private void OnDrawGizmosSelected()
{
Gizmos.color = IsColliderDetected ? Color.green : Color.red;
Gizmos.DrawWireCube(transform.position, transform.lossyScale);
}
#endif
}
}