int[] help
Hi, I have a variable in which the values specified in unity 5 are stored and I have not a damn thing working
float money = stream.Money;
float income = stream.Income;
public int[] price_cpu;
public int cur_price_cpu;
public float multiplication_cpu;
public void Upgrade_CPU()
{
if (money >= price_cpu[cur_price_cpu])
{
money -= cur_price_cpu;
income += multiplication_cpu;
}
}
What specifically isn't working? Without knowing what this code is supposed to do or where it's going wrong, we can't help you fix it.
There is a list price_cpu the price of which is set in the inspector unity 5, I need to take the first variable from this list and check whether there is enough money to buy, if there is enough, then the + bonus "multiplication_cpu" is bought and the sheet should add +1 For example, if 1 purchase costs 10 then it is checked if the player has money and if there is an improvement is bought and +1 is added to the list (cur_price_cpu)
float money = stream.$$anonymous$$oney;
float income = stream.Income;
public int[] price_cpu; // list in unity 5
public int cur_price_cpu; // takes price in list
public float multiplication_cpu; // income
public void Upgrade_CPU()
{
if (money >= price_cpu[cur_price_cpu]) //
I think that's the mistake here price_cpu[cur_price_cpu]
{
cur_price_cpu++;// +1 to upgrade level
money -= cur_price_cpu; // - money
income += multiplication_cpu; // + to money
}
}
public void UpgradeCpu()
{
Debug.Log("UpgradeCpu Clicked!");
if (cur_price_cpu < price_cpu.Length && money >= price_cpu[cur_price_cpu])
{
Debug.Log("$$anonymous$$oney before purchase : " + money + " Current cpu price : " + price_cpu[cur_price_cpu]);
money -= price_cpu[cur_price_cpu];
Debug.Log("$$anonymous$$oney after purchase : " + money);
cur_price_cpu++;
Debug.Log("Income before purchase : " + income);
income += multiplication_cpu;
Debug.Log("Income after purchase : " + income);
}
}
Does this work? Do you get the UpgradeCpu Clicked!
in the Log window?
Your answer
![](https://koobas.hobune.stream/wayback/20220612140302im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Accesing specific int from inspector 2 Answers
Coin Spending/PlayerPref Subtracting 0 Answers
Integer arrays not comparing properly. 3 Answers
Integer multiplies itself by 3 for seemingly no reason 0 Answers