MonoBehaviour OnMouseUpAsButton and new GUI clickthrough

OK, here’s the thing: I have simple script for selecting objects in my custom-built level editor, based on MonoBehaviour’s OnMouseUpAsButton.

void OnMouseUpAsButton() {
		LevEditGlobals.currentGO = this.gameObject;

As you can see, code is very simple and it works fine. Unfortunately, there is unforeseen… interaction with new GUI (that is used for in-game object inspector) - when I click control that is over some “selectable” game object, both actions (selecting object, often wrong and clicking gui) are performed. Why does it happen and how can I fix it?

You can use EventSystem.IsPointerOverGameObject to filter out UI clicks. Add it to the script that’s looking for clicks on your selectable game objects…

if (!EventSystem.current.IsPointerOverGameObject())
  // the mouse is over one of your objects and NOT over
  // a UI object so do your game object select stuff here