-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInventory.cs
39 lines (37 loc) · 821 Bytes
/
Inventory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Inventory<T>
{
static private Dictionary<T, int> inventory;// = new();
/*
public static Inventory<T> Instance = null;
public void Awake()
{
if (Instance == null)
Instance = this;
}*/
public Inventory()
{
inventory = new();
}
public void Push(T item)
{
if (!inventory.ContainsKey(item))
inventory[item] = 1;
else
inventory[item]++;
}
public T Pop(T item)
{
if (inventory.ContainsKey(item))
{
if (inventory[item] > 1)
inventory[item]--;
else
inventory.Remove(item);
return item;
}
return default;
}
}