- Home /
right mouse down on a gameObject
Hey, so here's something I'm trying to figure out. I have two boxes in a scene that I want to rotate when the right button is held down on each box and dragged left and right. so moving the mouse left would make the object rotate one direction and vice versa.. I've kinda figured out how to do this using the left mouse button. problem is I don't know what to use for "onMouseDown" and "onMouseUp" when using the right mouse button.. I can simply use if(Input.GetMouseButtonDown(1)){} but this wouldn't detect if the mouse is on the object.... any help would be greatly appreciated, thanks!
Answer by IJM · Nov 18, 2010 at 07:10 AM
You can use "OnMoseOver" that is something like "Update" but it's called only when the pointer is over the object:
function OnMouseOver ()
{
if(Input.GetMouseButtonDown(0))
Debug.Log("Left click on this object");
if(Input.GetMouseButtonDown(1))
Debug.Log("Right click on this object");
if(Input.GetMouseButtonDown(2))
Debug.Log("Middle click on this object");
}
remember that this only gets called on $$anonymous$$onobehaviours which has a collider on it or is a GUIElement.
Wow tysm you helped me even 11 years after posting the answer
Answer by GFX47 · Apr 04, 2011 at 02:28 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! ;)
Your answer
![](https://koobas.hobune.stream/wayback/20220613083524im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Click and Drag Camera 3 Answers
How to disable button OnClick when drag on the screen with OnMouseDrag 2 Answers
Right mouse detection 2 Answers
How to check for a mouse drag 0 Answers
OnMouseUp() Click Display Effect. 1 Answer