Some checks failed
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (push) Successful in 16m25s
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (push) Successful in 13m9s
Build project / Publish to itch.io (StandaloneLinux64) (push) Successful in 9s
Build project / Publish to itch.io (StandaloneWindows64) (push) Successful in 9s
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (pull_request) Has been cancelled
Build project / Publish to itch.io (StandaloneLinux64) (pull_request) Has been cancelled
Build project / Publish to itch.io (StandaloneWindows64) (pull_request) Has been cancelled
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (pull_request) Has been cancelled
62 lines
1.9 KiB
C#
62 lines
1.9 KiB
C#
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;
|
|
// }
|
|
}
|
|
} |