resource limits added
This commit is contained in:
@ -69,5 +69,6 @@ public class Inventory : MonoBehaviour
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
67
Assets/Scripts/Inventory/TempInventory.cs
Normal file
67
Assets/Scripts/Inventory/TempInventory.cs
Normal file
@ -0,0 +1,67 @@
|
||||
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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/Inventory/TempInventory.cs.meta
Normal file
11
Assets/Scripts/Inventory/TempInventory.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0409b6b23ffc72640a6491311e0f6a26
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user