Reputation: 517
I have two 2D game objects. They each have a Box Collider 2D and a Rigid Body 2D which is not kinematic. When the game plays, one moves towards the other and collides with it.
However, I also have the following method in the moving GameObject:
void OnCollisionEnter(Collision collision)
{
print( "Collided with someone" );
}
The print statement never prints, so presumably the method is never called. Where am I going wrong?
Upvotes: 12
Views: 30739
Reputation: 2802
Unity has replicated all of the physics methods for 2D with the word "2D" stuck onto the end! So for your example, it should be changed to:
void OnCollisionEnter2D(Collision2D collision)
And the same with basically any other 2D physics thing.
Upvotes: 27