Example #1
0
    public void SellItem(ShopItem shopItem)
    {
        //decrease number in SellWindow
        shopItem.item.amount -= 1;
        if (shopItem.item.amount == 0)
        {
            GameObject.Destroy(shopItem.gameObject);
        }
        else
        {
            shopItem.gameObject.GetComponentsInChildren <Text>()[2].text = shopItem.item.amount.ToString();
        }

        //increase number in BuyWindow
        List <ShopItem> tempList = new List <ShopItem>(buyWindow.GetComponentsInChildren <ShopItem>());

        int index = tempList.FindIndex(i => i.item.id == shopItem.item.id);

        if (index >= 0)
        {
            tempList[index].item.amount += 1;
            tempList[index].gameObject.GetComponentsInChildren <Text>()[2].text = tempList[index].item.amount.ToString();
        }
        else
        {
            Item newItem = new Item(shopItem.item);
            newItem.amount = 1;
            GameObject newRow = InstantiateItem(newItem, buyWindow.transform);
        }

        //update balance UI
        shopBalance += float.Parse(shopItem.GetComponentsInChildren <Text>()[1].text, NumberStyles.Currency);
        UpdateUI();
    }