- Home /
inventory system: drop item with mouseclick
Hi!
I want to drop a item that is currently attached to the cursor by clicking on the screen outside the inventory or other GUI elements.
When i use Input.GetMouseButtonDown it will always drop the item, even if i click on a free inventory slot.
How does one detect if no GUI elemt is hit when clicking?
Answer by Berenger · Jan 28, 2013 at 01:47 PM
You need to check if the click occured over a free space of the screen, without GUI. For that, there is the function Rect.Contains. You'll have to check every rect, or the one that contains them all.
Or, there is the tooltip. before any GUI is drawn, draw an empty label the size of the screen with a specific tooltip ("background", for inst). Then, check and store the tooltip in the GUI loop. And when you click, you can check if tooltip == "background".
In both case, you'll need a centralised GUI, inside one function with a list of stuff to draw. I hope I'm making sense ...