clean up code
Some checks failed
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (push) Has been cancelled
Build project / Publish to itch.io (StandaloneLinux64) (push) Has been cancelled
Build project / Publish to itch.io (StandaloneWindows64) (push) Has been cancelled
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (push) Has been cancelled

This commit is contained in:
nlevin6 2025-03-29 21:40:27 -04:00
parent 930173c383
commit ef45838c22
3 changed files with 10 additions and 30 deletions

View File

@ -3,8 +3,7 @@ using System.Collections.Generic;
public class Inventory : MonoBehaviour
{
// A fixed array of 10 slots
[Header("Exactly 10 Slots")]
[Header("10 Inventory Slots")]
public Item[] slots = new Item[10];
public int currentSlot = 0;
@ -25,9 +24,6 @@ public class Inventory : MonoBehaviour
}
}
/// <summary>
/// Adds an item to the first available slot (if any).
/// </summary>
public void AddItem(Item newItem)
{
for (int i = 0; i < slots.Length; i++)
@ -38,8 +34,6 @@ public class Inventory : MonoBehaviour
break;
}
}
// Optional: if no item is equipped yet, equip slot 0, etc.
// if (currentSpawnedItem == null) EquipSlot(0);
}
private void SelectNextSlot()
@ -47,7 +41,6 @@ public class Inventory : MonoBehaviour
currentSlot = (currentSlot + 1) % slots.Length;
EquipSlot(currentSlot);
// Force the UI to re-check which slot is active
var ui = FindObjectOfType<InventoryUI>();
if (ui != null)
{

View File

@ -3,10 +3,8 @@ 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 Image[] slotImages;
[SerializeField] private Inventory inventory;
[SerializeField] private Color normalColor = Color.white;
[SerializeField] private Color highlightColor = Color.yellow;
@ -28,31 +26,26 @@ public class InventoryUI : MonoBehaviour
else
{
slotImages[i].sprite = null;
slotImages[i].color = new Color(1,1,1,0); // or Color.clear
slotImages[i].color = new Color(1, 1, 1, 0);
}
}
HighlightSlot(inventory.currentSlot); // after we set sprites, highlight the active slot
HighlightSlot(inventory.currentSlot);
}
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
slotImages[i].color = new Color(1, 1, 1, 0);
else
slotImages[i].color = normalColor;
}
// Now highlight the active slot
slotImages[slotIndex].color = highlightColor;
}
}

View File

@ -48,22 +48,18 @@ public class PickUpKeyCard : MonoBehaviour
{
isPickedUp = true;
// Mark key card as picked up in your custom script
if (keyCardPlayer != null)
keyCardPlayer.hasKeyCard = true;
// Add the keycard to player's inventory
if (playerInventory != null && keyCardItem != null)
{
playerInventory.AddItem(keyCardItem);
gameObject.SetActive(false);
// Refresh the UI
InventoryUI inventoryUI = FindObjectOfType<InventoryUI>();
if (inventoryUI != null)
{
inventoryUI.RefreshUI();
}
Destroy(gameObject);
}
if (outline != null)
@ -72,11 +68,9 @@ public class PickUpKeyCard : MonoBehaviour
if (interactionPrompt != null)
interactionPrompt.enabled = false;
// Play pickup animation
if (objectAnimator != null)
objectAnimator.Play(animationName, 0, 0.0f);
// Play sound
if (pickupSound != null)
SoundFXManager.instance.PlaySound(pickupSound, transform, 1.5f);
}