- Home /
OnMouseDown() won't work unless gameObject's 2DBox Collider - ‘Is Trigger’ is toggled on/off mid-game in editor.
No matter what the state of ‘Is Trigger’ is, once toggled once, the gameObject's OnMouseDown() can be triggered again. If I keep ‘Is trigger’ on and start the game, the onMouseDown() function only works if I toggle it off mid-game. If the ‘Is Trigger’ is checked off, the OnMouseDown() function only worked if I toggle it on mid-game.
Edit: The same behaviour also happens when I toggle Box Collider’s ‘Used By Effector'
OnMouseDown() posts a Debug.Log (“message”) when gameObject is clicked. This originally was not being posted to my console, making me think that my gameObject didn’t know it was being clicked.
A CS script with OnMouseDown() is attached to the game object
A Box Collider is standard (ie no Physics Material has been added or anything) and attached to the game object
What's going on?
In every instance of your description you've said on$$anonymous$$ouseXX (with lowercase o) whereas the Unity functions are On$$anonymous$$ouseXX (with uppercase O); please clarify
@getyour411 Sorry. The On$$anonymous$$ouseDown() functions all have uppercase O's in my code.
Just had this exact same thing happen to me. Banged my head against the wall for 2 hours, could not figure it out. Ended up deleting the object in question and adding an entirely new one and it worked fine. Would love to know if there is something I did to cause this though.
@EhBan Actually, your fix was the same as $$anonymous$$e. I didn't post it as an answer because I wasn't sure if deleting the gameObject and then recreating the same thing counted as a solution. It must be a Unity bug. It's good to know i'm not the only one.