I am trying to make an interface where the player can pick up items from the ground, and then organize their inventory via “inventory slots”. Simple stuff, you’d think. (No different than most games with inventory slots in your “bag”/“backpack” and item icons).
So the player clicks an item in game, and it disappears in the game world and appears as a GUI Icon following the mouse position.
However, this is when the entire system messes up. To make sure I don’t “Click To Move” when I click the GUI, I have to make sure that the mouse is not hovering over a GUI object.
if (Input.GetMouseButton (0) && EventSystem.current.IsPointerOverGameObject() == false
However, this means that whenever the player picks up an item, and the GUI Icon appears at the mouse (and follows the mouse), then player can no longer move.
Furthermore, the player can no longer click any GUI buttons. The mouse always seems to click only the GUI object which follows the player’s mouse. I’ve tried just not allowing player movement when holding an item in the mouse (I’m just trying to prototype this quickly), but this still doesn’t allow me to click any other GUI objects with the component if the player is “holding something” (GUI Icon following mouse, always in front of all gui button objects)
I’ve done my research, but am right now stumped and would prefer not to have to figure this out for hours if someone else knows a good solution.
I’ve read that with other GUI solutions (ex. NGUI) one could simply raycast and then check the names of all the GUI objects hit. I find no such functionality in Unity’s new GUI. Any raycasting I do, ignores the GUI and simply raycasts in the 3D world. (Perhaps I am doing the raycasting wrong?)
The GUI Icon which follows the mouse, is just an Image (Script) component. If I hide the “Image (Script)” component, it allows me to click on any and everything. Obviously though, I cannot do this, as that is the entire point of the GUI Icon.