Skip to Content
Mastering UI Development with Unity
book

Mastering UI Development with Unity

by Dr. Ashley Godbold
April 2018
Beginner content levelBeginner
468 pages
11h 7m
English
Packt Publishing
Content preview from Mastering UI Development with Unity

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) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Game Development with Unity for .NET Developers

Game Development with Unity for .NET Developers

Jiadong Chen
Unity UI Cookbook

Unity UI Cookbook

Francesco Sapio

Publisher Resources

ISBN: 9781787125520Supplemental Content