Hi,
I used mouse click move in my game, use raycast to identify where to go by transform click point on screen. Here is question now, I added gui on my screen, now when mouse click on gui, I wanna it works like on regular gui, but not still the mouse move action, how can I do it?
Manully justify whether the mouse click point is inner of gui area? That is not good I think…
Thanks in advance.
No one knows?
I think this should be common case when develop one game. You must figure out what is user clicked on, on the gui or on one 3d object…
I will keep diggin into, but if someone has experience on it, pls help me on this:)
Do you want to be able to click on both GUI and 3D objects in the same game state, or do you want to switch between modes? For example: An escape menu mode where you can load and save games, and a running mode where the game is actually running.
This is one solution but I think it can be more flexible. For example, there is one user instant message window, when user click on the textbox, it gets focus and user can input his message now, but if user click on other area in the game screen, it does player move action.
The way to do this is to check if the mouse position is in any of the GUI controls’ rectangles before performing the raycast (you can use Rect.Contains to see if a point is in a rectangle).
en… I have considered this way, it should work theorerical. But in my case, there are several windows, they are draggable and are dynamically generated or vanished by user input; If I make one list to remember all the active windows and do check before any user click, it should work…
But still, is there no more convenient way unity supplied to accomplish this goal?
I created my own GUI “widget” system on top of Unity’s GUI library.
But underneath it’s doing the same thing: each of my Widgets knows the Rect size and whenever there’s a mouse click, it checks to see which Widget, if any, is under the mouse pointer. If one exists, it sends off an “on_widget” event to my event system to the correct widget; if not, it sends an “on_click” event to the world system.
Don’t be afraid to treat Unity’s GUI system (and others) as building blocks for your own customized library that does things perfectly how you want.