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
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:
parent
930173c383
commit
ef45838c22
@ -3,8 +3,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
public class Inventory : MonoBehaviour
|
public class Inventory : MonoBehaviour
|
||||||
{
|
{
|
||||||
// A fixed array of 10 slots
|
[Header("10 Inventory Slots")]
|
||||||
[Header("Exactly 10 Slots")]
|
|
||||||
public Item[] slots = new Item[10];
|
public Item[] slots = new Item[10];
|
||||||
|
|
||||||
public int currentSlot = 0;
|
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)
|
public void AddItem(Item newItem)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < slots.Length; i++)
|
for (int i = 0; i < slots.Length; i++)
|
||||||
@ -38,8 +34,6 @@ public class Inventory : MonoBehaviour
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Optional: if no item is equipped yet, equip slot 0, etc.
|
|
||||||
// if (currentSpawnedItem == null) EquipSlot(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SelectNextSlot()
|
private void SelectNextSlot()
|
||||||
@ -47,7 +41,6 @@ public class Inventory : MonoBehaviour
|
|||||||
currentSlot = (currentSlot + 1) % slots.Length;
|
currentSlot = (currentSlot + 1) % slots.Length;
|
||||||
EquipSlot(currentSlot);
|
EquipSlot(currentSlot);
|
||||||
|
|
||||||
// Force the UI to re-check which slot is active
|
|
||||||
var ui = FindObjectOfType<InventoryUI>();
|
var ui = FindObjectOfType<InventoryUI>();
|
||||||
if (ui != null)
|
if (ui != null)
|
||||||
{
|
{
|
||||||
|
@ -3,10 +3,8 @@ using UnityEngine.UI;
|
|||||||
|
|
||||||
public class InventoryUI : MonoBehaviour
|
public class InventoryUI : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] private Image[] slotImages; // 10 UI Images
|
[SerializeField] private Image[] slotImages;
|
||||||
[SerializeField] private Inventory inventory; // The fixed-slot Inventory
|
[SerializeField] private Inventory inventory;
|
||||||
|
|
||||||
// These let you pick highlight/normal colors in the Inspector
|
|
||||||
[SerializeField] private Color normalColor = Color.white;
|
[SerializeField] private Color normalColor = Color.white;
|
||||||
[SerializeField] private Color highlightColor = Color.yellow;
|
[SerializeField] private Color highlightColor = Color.yellow;
|
||||||
|
|
||||||
@ -28,31 +26,26 @@ public class InventoryUI : MonoBehaviour
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
slotImages[i].sprite = null;
|
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)
|
private void HighlightSlot(int slotIndex)
|
||||||
{
|
{
|
||||||
// Make sure it's a valid index
|
|
||||||
if (slotIndex < 0 || slotIndex >= slotImages.Length)
|
if (slotIndex < 0 || slotIndex >= slotImages.Length)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Set all slots to normal color
|
|
||||||
for (int i = 0; i < slotImages.Length; i++)
|
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)
|
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
|
else
|
||||||
slotImages[i].color = normalColor;
|
slotImages[i].color = normalColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now highlight the active slot
|
|
||||||
slotImages[slotIndex].color = highlightColor;
|
slotImages[slotIndex].color = highlightColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,11 @@ public class PickUpKeyCard : MonoBehaviour
|
|||||||
private Outline outline;
|
private Outline outline;
|
||||||
|
|
||||||
[SerializeField] private Animator objectAnimator;
|
[SerializeField] private Animator objectAnimator;
|
||||||
[SerializeField] private string animationName = "PickupAnimation";
|
[SerializeField] private string animationName = "PickupAnimation";
|
||||||
[SerializeField] private AudioClip pickupSound = null;
|
[SerializeField] private AudioClip pickupSound = null;
|
||||||
[SerializeField] private string keyCardName = "Deck D key card";
|
[SerializeField] private string keyCardName = "Deck D key card";
|
||||||
|
|
||||||
[SerializeField] private KeyCardPlayer keyCardPlayer = null;
|
[SerializeField] private KeyCardPlayer keyCardPlayer = null;
|
||||||
[SerializeField] private float interactionDistance = 5.0f;
|
[SerializeField] private float interactionDistance = 5.0f;
|
||||||
|
|
||||||
[SerializeField] private Item keyCardItem;
|
[SerializeField] private Item keyCardItem;
|
||||||
@ -48,22 +48,18 @@ public class PickUpKeyCard : MonoBehaviour
|
|||||||
{
|
{
|
||||||
isPickedUp = true;
|
isPickedUp = true;
|
||||||
|
|
||||||
// Mark key card as picked up in your custom script
|
|
||||||
if (keyCardPlayer != null)
|
if (keyCardPlayer != null)
|
||||||
keyCardPlayer.hasKeyCard = true;
|
keyCardPlayer.hasKeyCard = true;
|
||||||
|
|
||||||
// Add the keycard to player's inventory
|
|
||||||
if (playerInventory != null && keyCardItem != null)
|
if (playerInventory != null && keyCardItem != null)
|
||||||
{
|
{
|
||||||
playerInventory.AddItem(keyCardItem);
|
playerInventory.AddItem(keyCardItem);
|
||||||
gameObject.SetActive(false);
|
|
||||||
|
|
||||||
// Refresh the UI
|
|
||||||
InventoryUI inventoryUI = FindObjectOfType<InventoryUI>();
|
InventoryUI inventoryUI = FindObjectOfType<InventoryUI>();
|
||||||
if (inventoryUI != null)
|
if (inventoryUI != null)
|
||||||
{
|
|
||||||
inventoryUI.RefreshUI();
|
inventoryUI.RefreshUI();
|
||||||
}
|
|
||||||
|
Destroy(gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outline != null)
|
if (outline != null)
|
||||||
@ -72,11 +68,9 @@ public class PickUpKeyCard : MonoBehaviour
|
|||||||
if (interactionPrompt != null)
|
if (interactionPrompt != null)
|
||||||
interactionPrompt.enabled = false;
|
interactionPrompt.enabled = false;
|
||||||
|
|
||||||
// Play pickup animation
|
|
||||||
if (objectAnimator != null)
|
if (objectAnimator != null)
|
||||||
objectAnimator.Play(animationName, 0, 0.0f);
|
objectAnimator.Play(animationName, 0, 0.0f);
|
||||||
|
|
||||||
// Play sound
|
|
||||||
if (pickupSound != null)
|
if (pickupSound != null)
|
||||||
SoundFXManager.instance.PlaySound(pickupSound, transform, 1.5f);
|
SoundFXManager.instance.PlaySound(pickupSound, transform, 1.5f);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user