[SOLVED] Ball collisions are not being detected: OnCollisionEnter2D NOT OnCollisionEnter2d

still cant play the boing sound but the crack sound works now. Chased this down to ball 2dcollisions are not being detected (put in a print message into ball and it is never played).

tried to get all this uploaded to Github as best I could (not very familiar with it, sorry):

please help if you can

going on in lecture I am getting an error that “type Ball does not contain a definition for rigidbody 2d”

doesn’t seem to indicate whether its my ball prefab or the ball material

Hello @walshlg

Don’t know if its just me, but I can’t view the source on github.
There is just the readme.md file.

Just added a screenshot o my ball-prefab.
You got that “rigidbody2D” in there?


are you using version 5.x of unity? I’m using 4.7 and my rigidbody pane is different, not showing Body Type Material or simulated.

Sorry about the problems with Github, I’m new to it and the directions seem to be involved in everything except for uploading and sharing files! Did their tutorial and its nonsense for the new user. Will try again

ok perhaps this one will work:

and here is my inspector panel

Hello @walshlg

New github-link is fine.
Gonna have a look at it. (may take some time)


Hello @walshlg.

In your Ball-script the collision is not detected.
I nearly had a mental-crack-up as your code looked ok so far. :smiley:

Took me some time to find out you wrote “OnCollisionEnter2d(…)” but it should be "OnCollisionEnter2D(…) with a capital “D”.

Hope that helps.



Thanks for your help, that was it, so simple and I looked at that line so many times!

I really appreciate you taking all this time and effort, a real journeyman effort.

Thanks again

1 Like

It was a Capital O in On and a capital D for 2D that got me. I also put in a console message which showed me the code wasn’t running and saved me messing about with various V5 changes I’d been looking at. Thanks for helping us newbies :slight_smile: Won’t forget to check case again.

Privacy & Terms