- Home /
OnMouseDown() intended behaviour
Hello i'm trying to use OnMouseDown to make possible to interact with objects. So far it's no real problem using it. But then i discovered one little thing that might force me to change all my script :
When i click with mouse left button it works fine, but doesn't rect with the other mouse buttons. Is this an intended behaviour or a bug?
Answer by BiG · Dec 16, 2011 at 01:11 PM
Yep, OnMouseDown() works only with left button. Checking for the pressure of a generic mouse button requires the implementation of an "overriding technique", that uses OnMouseOver(). A thing like this:
function OnMouseOver()
{
if (Input.GetMouseButtonDown(1)) //right button pressed
{
// OK, here you perform the action associated with right button
}
}
However, it seems to me that you have to perform the same action, independently from the button pressed: in this case, the script above is the same, just use a single if condition that includes all the desired buttons.
Well, i actually don't use those directly, ins$$anonymous$$d i use a bool to launch the calculations in OnGUI, that way i can use
Event.current.button
or, if it doesn't matter which mouse button :
if (Event.current.type == EvenType.$$anonymous$$ouseDown)
but thanks for the suggestion, till now i was searching for a solution somewhere far away from this simple one.
Your answer
Follow this Question
Related Questions
Does OnMouseUp() require OnMouseDown() to be triggered first? 1 Answer
Mathf.PerlinNoise not returning in Waves 1 Answer
Flickering Sprites 0 Answers
OnTriggerEnter not working all the time. 2 Answers