Quantcast
Channel: Answers for "If I have a button over my 3d world, how can I detect if a mouseClick was in the world or not?"
Viewing all articles
Browse latest Browse all 10

Answer by AngryAnt

$
0
0

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.

if (!GUIDidConsumeMouseDown (0) && Input.GetMouseDown (0))
{
    Debug.Log ("Click in the 3D world");
}

And the pseudocode logic to detect GUI event consumption:

  • OnGUI:
  • GUIDidGetMouseDown (Event.button) = Event.current.Type == EventType.MouseDown;
  • // The rest of your GUI //
  • GUIDidConsumeMouseDown (Event.button) = Event.current.Type == EventType.Used ? GUIDidGetMouseDown (Event.button) : false;

MonoBehaviour.OnMouseDown and friends automatically handles this - if you only rely on this functionality, you do not need to track GUI event consumption.


Viewing all articles
Browse latest Browse all 10

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>