示例#1
0
        public void BuyItem()
        {
            Player player = GameSingleton.Instance.GetPlayer();

            Player.Gamemode playerGamemode = player.gamemode;

            int gold = player.gamemode == Player.Gamemode.LEVEL
                ? player.gold
                : player.arcadeGold;

            if (gold >= item.price)
            {
                if (playerGamemode == Player.Gamemode.LEVEL)
                {
                    player.gold -= item.price;
                }
                else
                {
                    player.arcadeGold -= item.price;
                }
                ItemSlot boughtSlot = inventoryPrefab;
                boughtSlot.item        = item;
                boughtSlot.icon.sprite = icon.sprite;
                boughtSlot.itemName.SetText(itemName.text);
                _inventory.AddItem(boughtSlot.item);
                GameSingleton.Instance.soundManager.Play("Buy");
                _popup.Popup(Traducer.Translate("Bought ") + Traducer.Translate(item.name) + "!");
            }
            else
            {
                _popup.Popup(Traducer.Translate("Not enough gold!"), Color.red);
            }
        }