I'd like to know what the "0" stands for in this code:

if  (Input.GetMouseButtonDown (0))
// Do something here

When you have questions about how part of the built-in Unity API works, the best place to start is the Unity documentation.

On the page for Input.GetMouseButtonDown you'll find this:

public static bool GetMouseButtonDown(int button);

Returns true during the frame the user pressed the given mouse button.

You need to call this function from the Update function, since the state gets reset each frame. It will not return true until the user has released the mouse button and pressed it again.

button values are 0 for left button, 1 for right button, 2 for the middle button.

(Emphasis added)

One caveat to add here: 0 isn't necessarily the "left" button but the primary button. If the player has configured their mouse to be left-handed in their OS, with click-selection on the right button and context menus on the left, then 0 will register clicks from their right button, and 1 from their left.

(I've submitted feedback to Unity asking them to clarify this in the documentation)

There are definitely gaps in the documentation where you'll find you need to ask clarifying questions, but it's always worth taking a quick read first in case your answer is already published - much faster than waiting for a response here!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.