using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class HotbarUI : MonoBehaviour { public Inventory inventory; public ItemUseSystem itemUseSystem; public Transform slotContainer; public GameObject slotPrefab; public int slotCount = 10; private readonly List views = new List(); private void OnEnable() { if (inventory != null) { inventory.OnInventoryChanged += RefreshUI; } if (itemUseSystem != null) { itemUseSystem.OnSelectionChanged += RefreshUI; } BuildSlots(); RefreshUI(); } private void OnDisable() { if (inventory != null) { inventory.OnInventoryChanged -= RefreshUI; } if (itemUseSystem != null) { itemUseSystem.OnSelectionChanged -= RefreshUI; } } public void BuildSlots() { ClearSlots(); if (slotContainer == null || slotPrefab == null) { return; } for (int i = 0; i < slotCount; i++) { GameObject view = Instantiate(slotPrefab, slotContainer); view.SetActive(true); int capturedIndex = i; Button button = view.GetComponent