Unity Version 2019.4.12f1
I am attempting to detect a collision from a Box Collider 2D that is turned on and off when the player uses a certain attack. I have tried everything I can possibly think of as to why this isn’t working.
public void OnCollisionEnter2D(Collision2D col)
{
if (col.collider.name == "Bullet(Clone)")
{
health -= 1;
}
if (health <= 0)
{
Destroy(turret);
Debug.Log("turret destroyed");
}
if (col.collider.name == "shieldSlam")
{
isStunned = true;
stunnedTimer = 3;
}
}
}
The bullet detecting works perfectly fine. It is only the third if statement
that doesn’t work. It is not the way it is written, as I have substituted other Colliders in it’s place and it has functioned then.
I have tried: ensuring collision matrix is correct, ensuring one of them as a non-kinematic rigidbody, both have colliders, both have continuous collision detection, ensuring the attacks’ collider is ENABLED at the proper timing for collisions, ensuring z-position is accurate on both, trying to find it by tag rather than name, renaming it, un-childing the attack collider from player.
I am unsure as to what else I need to possibly check. I feel like I have been staring at this small issue for nearly 2 hours.