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