// Start is called before the first frame update
    void Start()
    {
        Shop = GetComponentInParent <TutorialShop>(); // Set shop

        // Get shop item from name
        ShopItem = Shop.ShopItems.FirstOrDefault(shopItem => shopItem.Name == ShopItemName);
        if (ShopItem == null)
        {
            Debug.LogWarning("Couldn't find shop item object for " + ShopItemName);
            BuyButton.interactable = false; // disable button
            text.text = "--";               // update buy button text
            return;
        }

        BuyButton.onClick.AddListener(() => Shop.BuyItem(ShopItem));

        Shop.UpdateBuyButtonVisual(ShopItem);
    }
示例#2
0
    public void BuyItem(TutorialShopItem shopItem)
    {
        // See if enough money and take money away
        if (shopItem.Price > Player.Money)
        {
            Debug.Log("You are too poor! :(");
            PopupManager.ShowBottomPopup("Not enough money...", Color.red, goodAlert: false);
            return;
        }

        Player.Money -= shopItem.Price;

        Debug.Log($"Buying {shopItem.Name}. Was level {shopItem.Level}");

        shopItem.Upgrade();              // Run function to upgrade

        BuySound.Play();                 // Play buy sound
        UpdateBuyButtonVisual(shopItem); // Update visuals
    }
示例#3
0
    public void UpdateBuyButtonVisual(TutorialShopItem shopItem)
    {
        Debug.Log("Update shop visual: " + shopItem.Name);

        var buyButton = GetComponentsInChildren <TutorialShopBuyButton>().First(buyButton => buyButton.ShopItem == shopItem);

        buyButton.text.text = "$" + shopItem.Price.ToString(); // Update price text

        // Prevent Overleveling
        if (shopItem.Level == shopItem.MaxLevel)
        {
            buyButton.BuyButton.interactable = false;
            buyButton.text.text = "Sold Out!";
        }
        else if (buyButton.BuyButton.interactable == false) // re-enable buy button
        {
            buyButton.BuyButton.interactable = true;
        }
    }
示例#4
0
    public static void FlowerBeds(TutorialShopItem shopItem)
    {
        FlowerBedManager.MakeFlowerBed(shopItem.Level - 1); // Create Flowerbed

        // Center Farm
        switch (shopItem.Level)
        {
        case 1:
            CenterFarm.bottomUnlocked = true;
            break;

        case 4:
            CenterFarm.topUnlocked = true;
            break;

        case 7:
            CenterFarm.leftSideUnlocked = true;
            break;
        }
    }