using System; using UnityEngine; [RequireComponent(typeof(BoxCollider2D))] public class HitBox : MonoBehaviour { public bool DoesDealDamage; public float DamageAmount; public float hitStunDuration; public Action TakeDamage; private BoxCollider2D _collider; private void Start() { _collider = GetComponent(); } private void OnTriggerStay2D(Collider2D other) { var otherHitBox = other.GetComponent(); if (otherHitBox != null && DoesDealDamage) { // do damage. Physics2D.IgnoreCollision(_collider, other); otherHitBox.TakeDamage(DamageAmount, hitStunDuration); } } private void OnTriggerExit2D(Collider2D other) { Physics2D.IgnoreCollision(_collider, other, false); } }