enum CoinType
{
Gold,
Silver
}
class Inventory
{
static Inventory()
{
}
private static Inventory localInventory { get; set; }
public static Inventory GetInventory()
{
if (localInventory == null)
localInventory = new Inventory();
return localInventory;
}
public void AddCoins(int count, CoinType type)
{
switch (type)
{
case CoinType.Gold:
this.Coins += count * 3;
break;
case CoinType.Silver:
this.Coins += count;
break;
}
}
public int Coins { get; private set; }
}
public class Player
{
private Inventory inventory;
public Player()
{
this.inventory = Inventory.GetInventory();
}
public void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.CompareTag("Coin"))
{
//Тип можно брать из метаданных монетки, там можно добавлять классы возможно enum тоже я не в курсе
this.inventory.AddCoins(1, CoinType.Silver);
Debug.Log("Количество монет = " + this.inventory.Coins);
Destroy(col.gameObject);
}
}
}