|
Hello! Is it possible to detect when the user clicks with the mouse outside a GUI's area? I wanted to call my GUI's close method when that happens but I have no idea how to detect such event in the correct way. Thanks!
(comments are locked)
|
|
Well there's no built in way to detect this. You have to check it manually. When you use a GUI window or group / area, you can use its Rect to check if the mouse is inside. Here's the same thing in UnityScript. i'm getting a strange error here: Event e = Event.current; the error says Assets/MyCustomScripts/GUI/Window.js(18,22): UCE0001: ';' expected. Insert a semicolon at the end. But there is a ; there... what the...
Aug 20 '12 at 11:51 AM
NeMewSys
This is the most efficient way I found of doing this: public function Update() { actually I don't know what's the difference between Event e = Event.current; and Input.GetMouseButtonDown(0).
Aug 20 '12 at 11:58 AM
NeMewSys
Damn it doesn't work, the OnMouseEnter and OnMouseExit are being applied to the GameObject and not the GUI itself....
Aug 20 '12 at 12:01 PM
NeMewSys
Uhmm, this example is written in C#...I've put a comment above that says C# ;) I can add the same example in UnityScript...
Aug 20 '12 at 12:22 PM
Bunny83
OnGUI is a very special callback. The Event class is tightly connected to OnGUI. All GUI elements are using the current Event state to draw themself or to react to all kind of events (keyboard / mouse / ...)
Aug 20 '12 at 12:28 PM
Bunny83
(comments are locked)
|
|
This is the closest as it gets so far:
I get the mouse coordinates X and Y, and check if they are in the GUI's boundaries, I guess this is the most efficient as it gets in GUIs. I wasn't able to use
because of that error i commented above. Hope this helps someone with the same question in the future. Thanks Can you post the relevant part of your GUI? What "area" do you have in your GUI?
Aug 20 '12 at 12:30 PM
Bunny83
My GUI's code is this: http://pastebin.com/H1AV3iW4 The relevant methods for this effect are Update and MouseOver.
Aug 20 '12 at 01:19 PM
NeMewSys
(comments are locked)
|

Still struggling with this, it was cool to have an OnClickOutside() method.
Not sure if this is what you want, but some initial investigation from me came up with Gui.changed http://docs.unity3d.com/Documentation/Components/gui-Controls.html at the bottom. may help