OnCollicionEnter2D doesn't work

Hello,
I have a problem with OnCollicionEnter2D. I made a code in script of main car. After this an enemy car should be destroyed but it’s not:

void OnCollicionEnter2D(Collision2D col)
{
if(col.gameObject.tag == “Enemy Car”)
{
Destroy(gameObject);
}
I tagged the enemy car “Enemy Car”. I can hit it with my car but that’s all. What could I do wrong?

Because you’re not spelling the function correctly. Please refer to documentation for it.

Oh my god, I didn’t notice that, thanks!

I could be wrong but won’t the above code destroy the object that the script is attatched to and not the enemy car?

1 Like

You’re correct; should be Destroy(col.gameObject).

1 Like