I’m working on a simple 2D game and I’m having trouble detecting collisions between two objects. I’m using rigid bodies and when I run the game, the collision detection does indeed work. But in my character script, I want to change the animation when that collision happens, but I don’t know how to call my collision function. Here’s my function:
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag == "enemy")
{
anim.SetBool ("isDead", true);
}
}
I’m pretty sure the function is correct, but I don’t know how to use it basically. How/Where should I call that function if a collision with the enemies occurs?