using UnityEngine; using UnityEngine.UI; public class InventoryUI : MonoBehaviour { [SerializeField] private Image[] slotImages; [SerializeField] private Image highlightImage; // Single highlight sprite [SerializeField] private Inventory inventory; [SerializeField] private Color normalColor = Color.white; void Start() { RefreshUI(); highlightImage.enabled = false; // Hide highlight initially } public void RefreshUI() { for (int i = 0; i < slotImages.Length; i++) { Item itemInSlot = inventory.slots[i]; if (itemInSlot != null && itemInSlot.itemIcon != null) { slotImages[i].sprite = itemInSlot.itemIcon; slotImages[i].color = normalColor; } else { slotImages[i].sprite = null; slotImages[i].color = new Color(1, 1, 1, 0); } } HighlightSlot(inventory.currentSlot); } private void HighlightSlot(int slotIndex) { if (slotIndex < 0 || slotIndex >= slotImages.Length) { // Debug.LogWarning("Slot index out of bounds: " + slotIndex); highlightImage.enabled = false; return; } // Only show highlight if the slot has an item // if (slotImages[slotIndex].sprite == null) // { // Debug.Log("Highlighting slot: " + slotIndex); highlightImage.transform.position = slotImages[slotIndex].transform.position; // move infront of the slot highlightImage.transform.SetAsLastSibling(); highlightImage.transform.localScale = slotImages[slotIndex].transform.localScale; highlightImage.color = new Color(1, 1, 1, 0.8f); // Semi-transparent highlightImage.enabled = true; // } // else // { // highlightImage.enabled = false; // } } }