Can i disable mouse click on other gameobjects when i click on a GUI?

Currently i have a floor, a character and a button on screen. Currently, if i click on any part of the floor, the character will walk there however when i press on the button, it will also move there which i don’t want. I am wondering is there any way to make raycast realized that i am clicking on a gui therefore not making the raycast. The making character move script is simply using raycast to determine the clicked position and move it there.

use something like Rect(0 0,100,100).Contains(Input.mousePosition) to exclude/include.

You would basically do a ! on the area of your GUI for the raytracing.

Thanks. Didn’t realized there’s a Contain method in rect. Thanks for the tips. :smile:

You could instead of seperating the two, do your click handling in a OnGUI function using the Event system. Without drawing anything in OnGUI for your script that does the click detection on the floors setting GUI.depth to a higher number will let other things take click events before it does. And when a click happens in the click detection OnGUI you can call .Use() on the event to declare ownership. This is probably the most ideal way to do it as it plays with the existing systems.

OnGUI gets called for every Event ( which is why sometimes a heavy GUI can slow things down because it can be ran multiple times per frame if alot of clicking or typing is going on and a large function )

I see. Maybe i can try this out. Thanks for the help :smile: