コード例 #1
0
    public void unlockNewChest()
    {
        ChestScript chestScript = actualChest.GetComponent <ChestScript>();

        //If there is otherChest to unlock
        if (listAllChest.Count != listUnlockChest.Count)
        {
            //deduct the money of the player
            player.money -= chestScript.getGoldToUnlock();
            //For all the item that we need to unlock the chest
            for (int i = 0; i < chestScript.getItemToUnlock().Count; i++)
            {
                //Check in inventory
                for (int j = 0; j < player.listIDItem.Count; j++)
                {
                    //If this is the right item
                    if (player.listIDItem[j] == chestScript.getItemToUnlock()[i].GetComponent <ItemScript>().id)
                    {
                        //deduct the number
                        player.listNumberItem[j] -= chestScript.getNumberItemToUnlock()[i];
                        //Refresh the number
                        TextMeshProUGUI textNumberItem = inventory.transform.GetChild(player.listSlotItem[j]).GetChild(1).GetComponent <TextMeshProUGUI>();
                        textNumberItem.text = "" + player.listNumberItem[j];
                        //If we use all the item
                        if (player.listNumberItem[j] == 0)
                        {
                            //remove from the inventory and reset the number to null
                            player.listNumberItem.RemoveAt(j);
                            player.listIDItem.RemoveAt(j);
                            inventory.transform.GetChild(player.listSlotItem[j]).GetChild(0).GetComponent <Image>().sprite = null;
                            textNumberItem.text = null;
                            player.listSlotItem.RemoveAt(j);
                        }
                    }
                }
            }
            //add to the unlockChest
            listUnlockChest.Add(listAllChest[player.actualChestNumber]);
            //Save the new timer and set it to the default timer
            player.listTimer.Add(listAllChest[player.actualChestNumber].GetComponent <ChestScript>().calculateTimer());
        }
        setChestSprite();
        setArrowActive();
    }
コード例 #2
0
ファイル: ControlMenu.cs プロジェクト: leodorn/ChestPhone
    private void setSlotToUnlock(GameObject panel)
    {
        bool canUnlock = true;
        //for each slot in unlockPanel
        ChestScript chestScript = chestImageScript.getActualChest().GetComponent <ChestScript>();

        for (int i = 0; i < chestScript.getItemToUnlock().Count; i++)
        {
            Transform transformSlot = panel.transform.GetChild(0).GetChild(i);
            //set the sprite with the item in the chestScript
            transformSlot.GetChild(1).GetComponent <Image>().sprite = chestScript.getItemToUnlock()[i].GetComponent <SpriteRenderer>().sprite;
            //set the number with the number in the chestScript
            transformSlot.GetChild(0).GetComponent <TextMeshProUGUI>().text = "" + chestScript.getNumberItemToUnlock()[i];
            //set the gold with the gold in the chestScript
            panel.transform.GetChild(2).GetChild(0).GetComponent <TextMeshProUGUI>().text = "" + chestScript.getGoldToUnlock();
            //(Put this because have some probleme with the next unlock)
            transformSlot.GetComponent <Image>().sprite = slotWrong;
            //Check the inventory
            bool findItem = false;
            for (int j = 0; j < player.listIDItem.Count && !findItem; j++)
            {
                //If we have the item
                if (player.listIDItem[j] == chestScript.getItemToUnlock()[i].GetComponent <ItemScript>().id)
                {
                    if (player.listNumberItem[j] < chestScript.getNumberItemToUnlock()[i])
                    {
                        if (canUnlock)
                        {
                            canUnlock = false;
                        }
                        //Set the red slot
                        transformSlot.GetComponent <Image>().sprite = slotWrong;
                    }
                    //If we have enought item
                    else if (player.listNumberItem[j] >= chestScript.getNumberItemToUnlock()[i])
                    {
                        //Set the red slot
                        transformSlot.GetComponent <Image>().sprite = slotRight;
                    }
                    findItem = true;
                }
            }
            if (!findItem)
            {
                canUnlock = false;
            }
            //Even if the inventory is empty
            if (player.listIDItem.Count == 0)
            {
                if (canUnlock)
                {
                    canUnlock = false;
                }
                transformSlot.GetComponent <Image>().sprite = slotWrong;
            }
            Image slotMoneyImage = panel.transform.GetChild(2).GetComponent <Image>();
            //If we don't have enought money
            if (player.money < chestScript.getGoldToUnlock())
            {
                if (canUnlock)
                {
                    canUnlock = false;
                }
                slotMoneyImage.sprite = slotWrong;
            }
            else
            {
                slotMoneyImage.sprite = slotRight;
            }
        }
        //active the unlock button and change the color of the button
        Transform transformUnlockPanel = panel.transform.GetChild(3);

        if (canUnlock)
        {
            transformUnlockPanel.GetChild(1).gameObject.SetActive(true);
            transformUnlockPanel.GetComponent <Image>().color = Color.white;
            transformUnlockPanel.GetChild(0).GetComponent <TextMeshProUGUI>().color = Color.white;
        }
        else
        {
            transformUnlockPanel.GetChild(1).gameObject.SetActive(false);
            transformUnlockPanel.GetComponent <Image>().color = new Color32(147, 147, 147, 226);
            transformUnlockPanel.GetChild(0).GetComponent <TextMeshProUGUI>().color = new Color32(149, 134, 134, 255);
        }
    }