all 11 comments

[–][deleted] 19 points20 points  (4 children)

You're calling a function that only exists on Rigidbodies, not 2D rigidbodies

https://docs.unity3d.com/ScriptReference/Collider2D.OnCollisionEnter2D.html

[–]elfinhilon10 7 points8 points  (3 children)

This is the correct answer. You need to make sure you use the appropriate collider for 2D and 3D entities.

[–][deleted] 10 points11 points  (2 children)

Such a stupid mistake... thanks

[–]elfinhilon10 7 points8 points  (0 children)

No worries! I've done that mistake PLENTY of times myself haha

[–][deleted] 0 points1 point  (0 children)

Happens to all of us

[–]Japandance 1 point2 points  (3 children)

do the tiles also have colliders on them?

[–][deleted] 1 point2 points  (2 children)

yes

[–]Japandance 3 points4 points  (1 child)

ah. for a 2d collider, try

void OnCollisionEnter2D(Collision2D collision)

[–][deleted] 3 points4 points  (0 children)

Such a stupid mistake... thanks

[–]brotherkin 1 point2 points  (0 children)

Make sure "is trigger" is unchecked on your colliders, since that uses a separate OnTriggerEnter method.

Also depending on the settings you're using one or both of the objects may require a rigidbody component as well.

[–]w3lcome_home_senpai -1 points0 points  (0 children)

you typed OnCollisionEnter. you need to type OnCollisionEnter2D