OnMouseDown gods fight through guitexture

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

When a mouse enters the gui object I do this

Code on a GUI GO:

 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;

  }

That seems like a MUCH better solution that what I currently have Tzan, thank you for sharing that!

andeeee: You really should beat that GUI coder of yours with a soft object (for now), because he posted in 2007 that this should be fixed asap :wink:

You’re welcome.

Maybe if a new GUI system gets put into Unity it will just work as expected.