Need Help On Knowing if Click happen on GUI. (OnGUI)

Hi everyone,

I’m trying to block my Click Input when i do a Click on a GUI. (OnGUI)

OnGUI doesn’t block the GetMouseButtonDown in other Script.
So i need to find a way to tell my other Script to not execute this click!

I can do something like that =>
Input.GetMouseButtonDown(0) && (MouseNotOnGUIFunction || Model.Variable.ToTellThatMouseIsNotOnGUI)

but i dont know how i can tell my mouse is over a GUI.

It’s a bit breaking the game if i dont implement this because its a Click to Move to MousePosition. So if we click OnGUI, the game move the player and we doesn’t want this behaviour!

Some help would be awesome :slight_smile:

Quite tricky with the old OnGUI - have you considered upgrading to the 4.6+ uGUI? There’s some great tutorials on how to use it and uprgade from the old OnGUI.

As @gcoops says, with the old GUI, it’s an ordeal. Basically, for each window or control you want to block interactions, somewhere in OnGUI, you have to check to see whether Event.current.mousePosition is inside that Rect. Then you set some global isMouseBlockedByGUI boolean, and check against that before you do mouse interaction.

…but yeah you should definitely consider using Unity UI, it’s precisely 27 times better than OnGUI.

Thx for the answers,

i will switch the GUI System in my 0.2.0 or 0.3.0 release at the moment im more on a Prototype so i need to show something pretty quickly and the new GUI i’m not familiar with it yet.

I found a way to do it, it’s not pretty Clean but will do the job for the 0.1.0 Prototype.