GetMouseButton()

Just with GetButton() and GetKey(), there are three functions for telling when a mouse button has been pressed: GetMouseButton(), GetMouseButtonDown(), and GetMouseButtonUp(). They return true in the same way that the GetButton() and GetKey() functions do.

You'd place these functions within the Update() function as well. Within the parentheses, you check to see which button is being pressed; 0 represents a left-click, 1 represents a right-click, and 2 represents a middle-click.

So, for example, if you wanted to check that the middle mouse button was clicked from the alphanumeric keyboard is being pressed, you could write the following code to trigger when the middle mouse button is pressed down:

void Update () {     if(Input.GetMouseDown(2) ...

Get Mastering UI Development with Unity now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.