コード例 #1
0
    // =============== On Btn Press ===============

    public void SelectItem(int select)
    {
        // Do on button press

        // Buy item
        if (!isBoughtList[currentIndex + select] && coins >= storeItems[currentIndex + select].price)
        {
            if (canChangeColor)
            {
                PlayerPrefs.SetInt("Bought Color " + (currentIndex + select), 1);
            }
            else if (canChangeSprite)
            {
                PlayerPrefs.SetInt("Bought Sprite " + (currentIndex + select), 1);
            }

            isBoughtList[currentIndex + select] = true;

            coins -= storeItems[currentIndex + select].price;
            gameManagement.coins = coins;
            otherStore.coins     = coins;
            coinText.text        = "COINS: " + coins;

            if (canChangeColor)
            {
                PlayerPrefs.SetInt("Current Color Selection", currentIndex + select);
            }
            else if (canChangeSprite)
            {
                PlayerPrefs.SetInt("Current Sprite Selection", currentIndex + select);
            }

            UpdateSelected();
            UpdateBought();
            ChangePlayerSprite(currentIndex + select);

            // Update other store on any selection changes
            otherStore.SetupStore();
            otherStore.UpdateBought();
            otherStore.UpdateSelected();
        }
        // If item is already bought and not selected, select it
        else if (isBoughtList[currentIndex + select] && (!(canChangeColor && PlayerPrefs.GetInt("Current Color Selection") == currentIndex + select) && !(canChangeSprite && PlayerPrefs.GetInt("Current Sprite Selection") == currentIndex + select)))
        {
            if (canChangeColor)
            {
                PlayerPrefs.SetInt("Current Color Selection", currentIndex + select);
            }
            else if (canChangeSprite)
            {
                PlayerPrefs.SetInt("Current Sprite Selection", currentIndex + select);
            }

            UpdateSelected();
            ChangePlayerSprite(currentIndex + select);

            otherStore.SetupStore();
            otherStore.UpdateBought();
            otherStore.UpdateSelected();
        }
    }