I have several guitextures in my game and i use onmousedown/up to register clicks. I also have some morens with the onmouseup functions, and if ond of those happens to be behind the guitexture, both Are executed. Is there a way to resolve this without turning to raycasting?
Edit: sorry about the weird headline, my iPad is auto-correcting words… Worst “feature” ever!
I don’t know about that… it certainly had me intrigued!
However, the gods will be disappointed. Currently, mouse events on one object don’t get “consumed”, so you get a report of the event in each OnMouseXXX function (which might sometimes be useful but is often a nuisance).
public void OnMouseEnter()
{
Globals.mouseIsOverGUI = true;
}
public void OnMouseExit()
{
Globals.mouseIsOverGUI = false;
}
It sets a global variable I can check.
If its true I ignore clicks on colliders behind the GUI
Code on a collider GO
// OnMouseDown() only activates on LMB
public void OnMouseDown()
{
//if the mouse is down on a GUITexture dont do anything
if (Globals.mouseIsOverGUI)
return;
SendMessageUpwards("SpaceClicked", id);
Globals.mouseIsDownSpace = true;
}