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.
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 }