|
My game is a 3d world. From time to time I want to display buttons ontop of the 3d world. How can I detect mosueclicks in the 3D world? If I use Input.GetMouseDown(), I also react on buttonclicks, which I don't want.
(comments are locked)
|
|
GUI receives mouse events one frame before Input does - you can use this fact to detect whether or not a mouse event was consumed by GUI when you're checking for mouse events in Input.
And the pseudocode logic to detect GUI event consumption:
MonoBehaviour.OnMouseDown and friends automatically handles this - if you only rely on this functionality, you do not need to track GUI event consumption.
(comments are locked)
|
|
Hi, been reading through some other postings and gathered some interesting things together that may help some other people reading this and needing a more complex solution for different reasons and using a window below the GUI.
var onMouseOverMenu : boolean = true;
var windowRect : Rect = Rect (20, 20, 200, 300);
var windowRectBox : Rect; function Update(){
} function OnGUI () { windowRectBox = GUI.Window (0, windowRect, WindowFunction, "My Window"); } function WindowFunction (windowID : int) { // Draw any Controls inside the window here
} e.g. if you have an onScreenDisplay wanting to show the distance to an object inside this screen: // place in Update()
(comments are locked)
|
|
use events such as mouse position and click count inside GUI button var gu : GUIText; var aa = 0 ; var aaa : String; function OnGUI(){
}
(comments are locked)
|
|
Use OnMouseDown() function in a script hanging on your GameObjects.
(comments are locked)
|
|
Use Worked like a charm for me! I used something like: if (GUIUtility.hotControl == 0) { //click is not on gui }
Nov 15 '12 at 04:51 PM
Emery Monzerol
(comments are locked)
|

So you want a GUI-like interface which will be transparent to mouse clicks, like a chat box, right? Nowadays that's not difficult to do at all. :)
cross-reference
http://answers.unity3d.com/questions/16774/preventing-mouse-clicks-from-passing-through-gui-c.html
http://answers.unity3d.com/questions/16587/gui-click-through.html