46 lines
1.2 KiB
C#
46 lines
1.2 KiB
C#
using UnityEngine;
|
|
|
|
public class PlayerInventory : Inventory
|
|
{
|
|
public static PlayerInventory instance;
|
|
|
|
private void Awake()
|
|
{
|
|
if (instance != null && instance != this)
|
|
{
|
|
Destroy(this.gameObject);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
instance = this;
|
|
}
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
// We can update the UI here because this is the Player's inventory
|
|
HealthBarUI.instance.UpdateGold(Gold);
|
|
}
|
|
|
|
// 'override' modifies the base AddItem method to add UI updates
|
|
public override void AddItem(string itemName, int quantity)
|
|
{
|
|
if (itemName == "Gold")
|
|
{
|
|
Gold += quantity;
|
|
HealthBarUI.instance.UpdateGold(Gold + quantity);
|
|
}
|
|
else
|
|
{ // This calls the base AddItem logic first
|
|
base.AddItem(itemName, quantity);
|
|
}
|
|
// Then, it adds the player-specific UI update
|
|
Debug.Log("Updating player UI for item: " + itemName);
|
|
// You would add your specific UI update logic here, e.g., UpdateInventoryUI();
|
|
}
|
|
public void ShotInventory()
|
|
{
|
|
Debug.Log(GetInventoryContentsAsString());
|
|
}
|
|
} |