using System.Collections.Generic;
using UnityEngine;
public class Inventory : MonoBehaviour
{
public List<Item> items = new List<Item>();
public int capacity = 20;
public bool AddItem(Item item)
{
if (items.Count >= capacity)
{
Debug.Log("Inventory is full!");
return false;
}
if (item.isStackable)
{
Item existingItem = items.Find(i => i.itemName == item.itemName);
if (existingItem != null)
{
// Stack logic (if needed)
Debug.Log($"Stacking {item.itemName}");
return true;
}
}
items.Add(item);
Debug.Log($"{item.itemName} added to inventory.");
return true;
}
public void RemoveItem(Item item)
{
if (items.Contains(item))
{
items.Remove(item);
Debug.Log($"{item.itemName} removed from inventory.");
}
}
public void UseItem(Item item)
{
if (items.Contains(item))
{
item.Use();
}
}
}
A basic setup for displaying the inventory items in the Unity UI.