OnRightMouseDown() ??

Why is there no function for this?

I’m going nuts trying to figure out something i’d think would be simple.

Probably not very common. Use this instead:

function OnMouseOver () {
	if (Input.GetMouseButtonDown(1)) {
		// something
	}
}

–Eric

Yeah, i’ve tried that.
Problem is that //something will run every frame instead of just once.

Suppose there’s no other alternative.

No, only the if statement runs every frame (that the mouse is over the collider), which is pretty trivial. //something only runs the one frame that the right mouse button is down.

–Eric

Yeah, that’s what i meant. It’ll run every frame the mouse is over the object with the button pressed.

I can find a way to work with it though.

You can also do something like

if(Input.GetButtonUp("Fire2")){
//Code here

which will be called once the user right clicks and lets go. Meaning it will only be called once per click.

From a performance standpoint you won’t notice anything, unless you have thousands of objects or something (but in that case you’d have other performance problems anyway :wink: ). Input in Unity is typically polled every frame anyway.

GetMouseButtonDown also is only called once per click. Except it’s called on mouse down rather than mouse up.

–Eric

Oops. For some reason I was thinking that it was called as long as the button was being held down! Learn something new every day.

GetMouseButton does indeed get called as long as it’s held down. But not GetMouseButtonDown. :slight_smile:

–Eric

You can also use this;

Input.GetButton(KeyCode.Mouse1);

We have to make a difference here, between a general right-mouseclick (Input.GetButton…) and a right-mouseclick on an object (GUIElement or Collider).
I also miss the MonoBehaviour.OnRightMouseDown (on an object), as Ramen Sama did with this post.
Surely, the solution is described by Eric5h5, but its a only a little workaround and the function seems to be missing.