Book Image

Creating E-Learning Games with Unity

By : David Horachek
Book Image

Creating E-Learning Games with Unity

By: David Horachek

Overview of this book

Table of Contents (17 chapters)
Creating E-Learning Games with Unity
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 highlighting of the GUI elements when they are selected or browsed:

void OnMouseOver() { // insert code here } 

Detecting leaving mouse over

A final callback method is called whenever the mouse leaves from over the top of a GameObject. This is the complement...