Пример #1
0
    private void PopulateShop()
    {
        for (int i = 0; i < shopItem.Length; ++i)
        {
            ShopItem   si         = shopItem[i];
            GameObject itemObject = Instantiate(shopItemPrefab, shopContainer);

            //ShopItem(Image, Button)
            // - Icon(Image)
            // - Price (TextMeshPro)
            // - Name (TextMeshPro)
            // - Time (TextMeshPro)

            //Change Icon
            itemObject.transform.GetChild(0).GetComponent <Image>().sprite = si.itemIcon;
            //Change Price
            itemObject.transform.GetChild(1).GetComponent <TextMeshProUGUI>().text = '$' + si.itemPrice.ToString();
            //Change Name
            itemObject.transform.GetChild(2).GetComponent <TextMeshProUGUI>().text = si.itemName;
            //Change Time
            cropTime = GameObject.FindGameObjectWithTag(si.itemName).GetComponent <crop0>();
            itemObject.transform.GetChild(3).GetComponent <TextMeshProUGUI>().text = '/' + cropTime.time.ToString() + 's';
            //Grab button, assign function
            itemObject.GetComponent <Button>().onClick.AddListener(() => OnButtonClick(si));
        }
    }
Пример #2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.CompareTag("character") && GetComponent <crop0>().cropAvailable)
        {
            for (int i = 0; i < inventory.slots.Length; i++)
            {
                if (inventory.slots[i].getName() == cropName)
                {
                    if (inventory.slots[i].getStack() < inventory.slots[i].maxStack)
                    {
                        inventory.slots[i].increaseStack();
                        inventory.slots[i].increaseStack();
                        stack = inventory.slots[i].getStack();
                        inventory.slots[i].setStack(stack.ToString());
                        Destroy(gameObject);
                        break;
                    }
                }
                if (!inventory.isFull[i] && inventory.slots[i].ifDeleted())
                {
                    Debug.Log("collide with character");
                    //item can be added
                    inventory.isFull[i] = true;

                    //set icon
                    inventory.slots[i].setSprite(shopIcon);

                    //set slot's name
                    inventory.slots[i].setName(cropName);

                    //set stack (to 2)
                    inventory.slots[i].increaseStack();
                    inventory.slots[i].increaseStack();

                    stack = inventory.slots[i].getStack();
                    inventory.slots[i].setStack(stack.ToString());

                    //is not empty
                    inventory.slots[i].SetisDeleted(false);

                    //X button enable
                    inventory.slots[i].Interactable(true);

                    //set Time
                    cropInfo = this.gameObject.GetComponent <crop0>();
                    inventory.slots[i].setCropTime(cropInfo.time);

                    Destroy(gameObject);
                    break;
                }
            }
        }
    }
Пример #3
0
    public void pushData()
    {
        try{
            try {
                crop0  cropStat = GetComponentInChildren <crop0>();
                PickUp pickUp   = GetComponentInChildren <PickUp>();
                this.timeLeft = cropStat.timeLeft;
                this.cropName = pickUp.cropName;
            } catch {
                Debug.Log("there is no crop on ground: " + gameObject);
                this.timeLeft = 0;
                this.cropName = "";
            }

            this.stat.dirtActive = this.dirtActive;
            this.stat.empty      = this.empty;
            this.stat.cropName   = this.cropName;
            this.stat.timeLeft   = this.timeLeft;
        } catch {
            Debug.Log("farming_ground push data error");
        }
    }