Adding press-and-hold/long-press functionality

Press-and-hold is utilized frequently in mobile games. Many games that use right-click on the PC or web use press-and-hold when they are converted to the mobile platform.

To demonstrate how to implement Press and Hold functionality, we will create a button that has a growing ring that represents hold time. Once a specified amount of time has passed, a function will fire:

When working this example, it is important to remember that even though the code is referencing a pointer, this functionality does not work exclusively with a mouse. Placing a finger on a touchscreen functions in the same way ...

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.