DIsplay item information when mouse hovers over UI element
Hi. I know this question has been asked multiple times, but I didn't find what I was looking for. Specifically, I have an InventoryGUI game object which parents some UI elements, included 12 slot game objects. I have set my UI up, and I have a script attached to the InventoryGUI gameobject, which acts like a game manager (displays/closes the inventory overlay, pauses the game, and holds a few user-defined functions to handle obtained items from the world).
Since this script was written for an older game, using legacy OnGUI() functionality, I modified it extensively to communicate with UI elements and the world. Back then, I tested if the slot rectangle contained the coordinates of the mouse, but this no longer works. I can successfully populate my inventory, so the system itself is functional. I'm also aware of the OnPointerEnter function, but as far as I understand, this has to be on a script attached to the object of interest; I want to control the slots from the main script (meaning, I want to check for a mouse hover inside the Update() of the Inventory script). Here's a snippet of code:
for (int i = 0; i < inventory.Count; i++)
{
int indexToString = i + 1;
GameObject tempSlot = GameObject.Find ("slot" + indexToString.ToString ());
RectTransform slotPosition = tempSlot.GetComponent<RectTransform>();
if ()
{
string itemText = inventory[i].itemDescription;
GameObject.Find ("invText").GetComponent<Text>().text = itemText;
Debug.Log("Mouse is over " + tempSlot.name);
break;
}
}
This checks if the inventory is open, then iterates through the inventory list, and depending on the index, typecasts the number and converts into a string to look for the actual GO (my slots are named slot1 to slot12). I want to figure out what I can put inside the if condition.