using System;
using System.Collections.Generic;
using UnityEngine;
[Serializable]
public class TempInventoryBuilderItem
{
public string name;
public int quantity;
}
public class TempInventory : MonoBehaviour
[SerializeField] private List<TempInventoryBuilderItem> initialInvent = new();
private readonly Dictionary<string, int> inventory = new();
// Start is called before the first frame update
private void Start()
foreach (var item in initialInvent) inventory[item.name] = item.quantity;
// Update is called once per frame
private void Update()
public int GetQuantityOf(string name)
if (inventory.ContainsKey(name)) return inventory[name];
return 0;
public bool Add(string name, int quantity = 1)
if (inventory.ContainsKey(name))
inventory[name] += quantity;
else
inventory.Add(name, quantity);
return true;
public bool Remove(string name, int quantity = 1)
inventory[name] = Mathf.Max(inventory[name] - quantity, 0);
return false;