Hi,
Is there a way to know when the right mouse button is down?
OnMouseDown tells me when the left mouse button goes down
OnMouseButtonDown differentiates between the buttons, but doesn’t register until the button goes back up
Hi,
Is there a way to know when the right mouse button is down?
OnMouseDown tells me when the left mouse button goes down
OnMouseButtonDown differentiates between the buttons, but doesn’t register until the button goes back up
Hmm… OnMouseDown only works for left mouse button(or whatever is set on the computer as left click)? Very interesting, I did not know that.
You could do something like this…
void OnMouseOver()
{
// Zero based. 1 is right mouse button.
if (Input.GetMouseButtonDown(1))
{
// Do stuff
}
}
This is of course you’re using it as intended(which I’ll assume you are) such that it works when clicking on the particular object the script resides in… and not just trying to determine the mouseclick in general regardless of context, which would simply require Input.GetMouseButtonDown
Excellent, thank you!
I hadn’t thought to use Input.GetMouseButtonDown(1)
I am attempting to modify the camera MouseOrbit script to have it do Zoom/Pan/Orbit depending on mouse button being pressed- traditional CAD examine mode controls.
So I did indeed want to determine input regardless of context. I had gotten as far as OnMouseButtonDown for the orbit, but was baffled for the Zoom (right button)
Next up- lots of confusing conversion math to turn cursor position into camera movement
Just a note, if you’re creating your camera orbit script so that it moves when you have the right mouse button HELD down so it fires repeatedly, rather than just a one shot thing, you’ll want to use Input.GetMouseButton instead of Input.GetMouseButtonDown
Also… the documentation says this.
If you are using input for any kind of movement behaviour use Input.GetAxis. It gives you smoothed and configurable input that can be mapped to keyboard, joystick or mouse.
So if you are in fact going to be holding the right mouse button for your camera pan, you’ll want to use Input.GetAxis rather than Input.GetMouseButton
Yes, definitely held down- I’ll try the Input.GetMouseButton instead
And yes, zoom and pan should be smooth- I’ll look into Input.GetAxis as well (never would have occured to me to look into that one)
Thanks again for all the pointers! The docs on this stuff are sometimes a bit sparse- unless you already know what you are doing
I know what you mean about the sparse documentation on some things. Had to deal with that myself. I’ve been taking tons of notes on various things so I won’t forget it in the future.