- Home /
Object.OnMouseDown vs Input.GetMouseButtonDown
This question applies to all of the OnMouseXXX and GetMouseButtonXXX and GetButtonXXX methods.
Can someone please explain the details under the hood and when should I chose one approach vs the other?
I'm seeing slight gotchas that I don't understand. Such as, according to the Execution Order, the OnMouseXXX events occur before Update. Cool, but it doesn't work on Right Click Mouse events and there doesn't appear to be a way for me to extend that functionality. So this forces me to handle right click events differently from left click events. Another oddity, the use of GetButtonXXX. It uses the Input Manager, so I can call GetButtonXXX("Fire2") to capture a mouse right click. That's cool, but what's up with GetMouseButtonXXX(1)? I thought maybe it was the mouse version of the GetKeyXXX, but KeyCode enum has mouse button enumeration.
I'm very confused. Between all of the different ways to handle input, I'm beginning to think that I need to abstract my own input class so it can cleanly handle all mouse events. But that feels wrong. Any advice appreciated.
Answer by awghulam555 · Jun 01, 2020 at 01:29 AM
I think OnMouseDown is for Rigid bodies and GetMouseButtonDown is used as a universal input. I am NOT saying that this may be correct. It may be wrong. This is just my guess, but I do know that they are basically the same thing. If one dosen't works, try the other. But both have a specific logic. I think that you'll be mostly fine with OnMouseDown
Your answer
Follow this Question
Related Questions
Multiple Players on one Computer/Console 5 Answers
Touch inputs on a Desktop type device 2 Answers
What's the entry name for mouse buttons in InputManager? 2 Answers
GetAxisRaw("Mouse X") not even close to manual mouse movement 0 Answers
Mouse Input Lag 3 Answers