- Home /
Other
testonCollisionEnter2D testwon't testget called on collison
After one hour of debuging im a little desperate and have to ask for help.
So in my 2D game I have two objects. One has a polygon collider and the other has a box collider. Triggers are switched off.
alt textalt text
Both objects have a Rigidboyd 2D attatched. Is Kinematic is switched off.
alt textalt text
The second object (the right screenshots) has 5 children attatched (This shouldn't be of importance as the collision only happens between the parent objects but who knows) Here is a screenshot of one child object. They are all identical.
alt text
My code (C#) (attatched to the second (right screenshots) object):
void onCollisionEnter2D(Collision2D other) { Debug.Log("attack"); }
I hope these are all important informations. I read through many posts with the same problem but it seems like all called the methode in a wrong way or have their colliders as triggers or their rigidbodys set to kinematic.
I hope you can help me. Thank you so much!
And sorry for my bad english im learning it at the moment.
Check the spelling its OnCollisionEnter2D (first letter is capital O).
Answer by zeppike · Jun 03, 2015 at 08:56 AM
All unity methods start with uppercase :) Use OnCollisionEnter2D() instead.
Wow! It really was that easy. I better don't tell you how long i debuged this or how long i read through forum posts (that only maybe had the same problem :))
Thank you!
Answer by BumblingIdiot · Jun 03, 2015 at 03:05 PM
The method is spelled wrong. C# uses camel case with an upper case letter at the start unlike other languages like java. Otherwise might be to do with the is trigger being ticked on your child objects. Try temporarily disabling them if just changing the method spelling doesn't work?