using UnityEngine; using UnityEngine.UI; public class InventoryUI : MonoBehaviour { [SerializeField] private Image[] slotImages; // 10 UI Images [SerializeField] private Inventory inventory; // The fixed-slot Inventory // These let you pick highlight/normal colors in the Inspector [SerializeField] private Color normalColor = Color.white; [SerializeField] private Color highlightColor = Color.yellow; void Start() { RefreshUI(); } 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); // or Color.clear } } HighlightSlot(inventory.currentSlot); // after we set sprites, highlight the active slot } private void HighlightSlot(int slotIndex) { // Make sure it's a valid index if (slotIndex < 0 || slotIndex >= slotImages.Length) return; // Set all slots to normal color for (int i = 0; i < slotImages.Length; i++) { // If the slot is empty, you might want to leave it "clear" // but let's just do normalColor for demonstration: if (slotImages[i].sprite == null) slotImages[i].color = new Color(1,1,1,0); // keep empty slot invisible else slotImages[i].color = normalColor; } // Now highlight the active slot slotImages[slotIndex].color = highlightColor; } }