O'Reilly logo

Creating E-Learning Games with Unity by David Horachek

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating clickable text elements

To process whether any of the preceding elements have been clicked or not by the mouse pointer, we have to manually program the handling of this event. Luckily for us, since these components are attached to a GameObject (which inherits from MonoBehavior), we can use mouse events that MonoBehavior provides.

Detecting mouse clicks

Whenever the mouse pointer is clicked while the pointer is over the top of a GameObject, the OnMouseDown callback is invoked. With this, we can trap these button clicks and respond accordingly:

void OnMouseDown() { // insert code here } 

Detecting mouse over

A second callback method is called whenever the mouse pointer moves onto a GameObject. This function is a convenient way to handle the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required