I meant to loop through all the colliders inside the range of this overlapCircle and do something (EnemyDeath) if the colliding objects meet some specific requirements (have a script attached). However what happens is that the overlapCircle range gets ignored and instead the EnemyDeath occurs when the box collider of the object with the script collides with the box collider of the enemy. Not at all what I intended.
public float circleRadius = 6f;
private void CheckForDestructible()
{
Collider2D[] overlappingColliders = Physics2D.OverlapCircleAll(transform.position, circleRadius);
foreach (Collider2D colliding in overlappingColliders)
{
if (canExplode == true)
{
var newExplosion = Instantiate(explosionFX, transform.position, Quaternion.identity);
Destroy(newExplosion, 0.5f);
Destroy(gameObject);
if (colliding.GetComponent<EnemyHealth>())
{
Debug.Log("boom, I killed an enemy");
colliding.GetComponent<EnemyHealth>().EnemyDead();
}
}
}
}