- Home /
The question is answered, right answer was accepted
Right mouse detection
Hello, I'm new in unity 3d, and I have a little script. There, I have a function OnMouseDown to detect when the mouse click. But, it works only with the left mouse button... I'm usig Input.GetMouseButton(1) to detect if the pressed mouse button is the right, but the OnMouseDown function only is called when I click with the left button.
Please help me!
Thanks....
Answer by Eric5h5 · Jun 06, 2010 at 04:26 AM
There isn't an OnMouseDown function for anything other than the left button, but you can sort of override OnMouseOver instead, like this:
function OnMouseOver () {
if (Input.GetMouseButton(1)) {
// do something
}
}
I'm using it, exactly like you show, but the function is called only when I click with the left mouse button .
With this script, only works the right mouse button if I press the two buttons.
But thanks for the help.
No, it works with the right button only. $$anonymous$$aybe you have another script interfering with it. And make sure you use On$$anonymous$$ouse*Over* not On$$anonymous$$ouse*Down*.
Thanks, I found a solution for my problem... I used the comparation in the Update function, and works for me.
On$$anonymous$$ouseDown
works also for touch on mobile platforms. I haven't tested, but I doubt this "override" would work for that. On top of it, no idea why Op accepted this answer while commenting he actually went another way, using Update
and probably Input.Get$$anonymous$$ouseButton
and some raycasting, which is more work but I think makes more sense. And it works for touching as well. @Leonardo you should post and accept your own solution!
Answer by GFX47 · Apr 04, 2011 at 02:27 PM
Here's a complete solution for right click detection: http://blog.gfx47.com/2011/04/04/detect-right-click-on-game-objects-in-unity3d/ Hope that will help! ;)