So… I have something like this:
Every time you hover one of these squares I would like to have that description window follow your mouse with a description of the object you are hovering. The problem is - my code is attached to the inventory window, and I can’t figure out how to get which of the individual slots is being hovered. I though I may be able to get to that with a lengthy math/ if statements mess, but is there a better/ simpler way to do that?
Here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class I_Inventory : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler{
public Image[] itemImages = new Image [itemSlots];
public I_Item[] items = new I_Item [itemSlots];
public const int itemSlots = 15;
public I_DetailWindow myDetailWindow;
public void AddItem (I_Item itemToAdd)
{
for (int i = 0; i < items.Length; i++) {
if (items [i] == null) {
items [i] = itemToAdd;
itemImages [i].sprite = itemToAdd.sprite;
itemImages [i].enabled = true;
return;
}
}
}
public void RemoveItem (I_Item itemToRemove)
{
for (int i = 0; i < items.Length; i++) {
if (items [i] == itemToRemove) {
items [i] = null;
itemImages [i].sprite = null;
itemImages [i].enabled = false;
return;
}
}
}
public void OnPointerEnter(PointerEventData eventData){
int i = 0; // Here - This number needs to change based on where you are hovering.
if (items [i]) {
myDetailWindow.myDescription = items [i].myDetails;
myDetailWindow.BringWindow ();
}
}
public void OnPointerExit(PointerEventData eventData){
myDetailWindow.EndWindow ();
}
(I_Item is a scriptable object holding the objects variables)
(Thank you!)
