예제 #1
0
    public override void OnUpdate()
    {
        foreach (UpgradeData upgrade in upgrades)
        {
            if (upgrade.item.IsJustPressed())
            {
                if (selected == upgrade && selected.CanBuy())
                {
                    if (PlayerData.Instance.Coins >= selected.price)
                    {
                        selected.Buy();
                        UpdateMessage();

                        //Update all the visuals (because of prerequisites)
                        foreach (UpgradeData upgradeVis in upgrades)
                        {
                            if (!upgradeVis.IsBought() && upgradeVis.prerequisite)
                            {
                                upgradeVis.UpdateVisual();
                            }
                        }

                        PlayerData.Instance.Coins -= selected.price;
                        PlayerData.Instance.Save();
                    }
                }
                else
                {
                    Select(upgrade);
                }
                return;
            }
        }

        /*
         * if(InputManager.Instance.IsTouch)
         * {
         *      Select(upgrades[0]);
         * }
         */

        if (backButton.IsJustPressed() || Input.GetKeyDown(KeyCode.Escape))
        {
            CoinsCounter.Instance.AnimateOut();
            MenuManager.Instance.SetPage(MenuManager.Instance.shopPage);
        }
    }