This repository has been archived on 2023-09-13. You can view files and clone it, but cannot push or open issues or pull requests.
station_obscurum_unity/Assets/Scripts/Inventory/TempInventory.cs

68 lines
1.4 KiB
C#

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<string,int> inventory = new Dictionary<string,int>();
[SerializeField]
private List<TempInventoryBuilderItem> initialInvent = new List<TempInventoryBuilderItem>();
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()
{
}
}