示例#1
0
    // Update is called once per frame
    void Update()
    {
        // might be updating this more than it needs to by having this in update
        goldAmt.text = $"Gold: ${goldManager.gold}";

        for (int i = 0; i < upgradeIndices.Length; i++)
        {
            // check if there are anymore upgrades left
            // might want to move some of this into SetUpgrade if
            // # of upgrades per obj becomes variable
            if (upgradeIndices[i] >= UpgradeLevels.GetUpgradesLength((UpgradeLevels.Types)i))
            {
                upgradeButtons[i].interactable = false;
            }
            // player/gold manager check if there's enough money for the next upgrade
            // if money is less than value, do nothing
            else if (goldManager.gold < UpgradeLevels.GetUpgrade((UpgradeLevels.Types)i, upgradeIndices[i]).cost)
            {
                upgradeButtons[i].interactable = false;
                upgradeCosts[i].color          = Color.red;
            }
            else
            {
                upgradeButtons[i].interactable = true;
                upgradeCosts[i].color          = Color.white;
            }
        }
    }
示例#2
0
    // Start is called before the first frame update
    void Start()
    {
        goldManager = goldManagerObject.GetComponent <Gold_Manager>();
        fishingRod  = fishingRodObject.GetComponent <FishingRod>();

        goldAmt = GameObject.Find("Current Gold").GetComponent <Text>();

        upgradeButtons = new Button[]
        {
            rodButton.GetComponent <Button>(),
            lineButton.GetComponent <Button>(),
            hookButton.GetComponent <Button>(),
            lureButton.GetComponent <Button>()
        };

        upgradeCosts = new Text[]
        {
            rodButton.transform.Find("cost").GetComponent <Text>(),
            lineButton.transform.Find("cost").GetComponent <Text>(),
            hookButton.transform.Find("cost").GetComponent <Text>(),
            lureButton.transform.Find("cost").GetComponent <Text>()
        };

        for (int i = 0; i < upgradeCosts.Length; i++)
        {
            upgradeCosts[i].text =
                $"${UpgradeLevels.GetUpgrade((UpgradeLevels.Types)i, upgradeIndices[i]).cost}";
        }
    }
示例#3
0
    /// <summary>
    /// Attempts to purchase upgrade of fishing rod part if player has enough money
    /// </summary>
    /// <param name="typeOfUpgrade">Part to upgrade</param>
    public void AttemptPurchase(UpgradeLevels.Types typeOfUpgrade)
    {
        // check if there are anymore upgrades left
        // might want to move some of this into SetUpgrade if
        // # of upgrades per obj becomes variable
        if (upgradeIndices[(int)typeOfUpgrade] >= UpgradeLevels.GetUpgradesLength(typeOfUpgrade))
        {
            return; // if no future upgrade exists don't do anything... no upgrade is left
        }
        // player/gold manager check if there's enough money for the next upgrade
        // if money is less than value, do nothing
        if (goldManager.gold < UpgradeLevels.GetUpgrade(typeOfUpgrade, upgradeIndices[(int)typeOfUpgrade]).cost)
        {
            return;
        }

        Debug.Log(typeOfUpgrade);


        // subtract the cost of the upgrade from the player's current gold tally
        goldManager.SubtractGold(UpgradeLevels.GetUpgrade(typeOfUpgrade, upgradeIndices[(int)typeOfUpgrade]).cost);

        // set upgradevalue
        UpgradeLevels.SetUpgrade(
            fishingRod,                        // rod reference
            typeOfUpgrade,                     // type of upgrade from enum in UpgradeLevels (written above this class)
            upgradeIndices[(int)typeOfUpgrade] // index of current upgrade
            );

        // increase index of upgrade
        upgradeIndices[(int)typeOfUpgrade]++;

        // set cost text
        if (upgradeIndices[(int)typeOfUpgrade] < UpgradeLevels.GetUpgradesLength(typeOfUpgrade))
        {
            upgradeCosts[(int)typeOfUpgrade].text =
                $"${UpgradeLevels.GetUpgrade(typeOfUpgrade, upgradeIndices[(int)typeOfUpgrade]).cost}";
        }
        else
        {
            upgradeCosts[(int)typeOfUpgrade].text = "$---";
        }
    }