Question by
Pixelvoice · Mar 11, 2016 at 01:29 AM ·
playerprefsintpaymentcoins
Problem with coin script and operands
Hey there fellow Unity devs!
I've having an issue with a coin payment script. I'm developing a small program that takes 25 coins to reveal a fortune. The payment script works but there's a snag. When the coins are less than 50 it switches to the else part of the method which says "not enough". This doesn't make sense because it's clearly stated that fortunes are 25 coins.
public int currentCoins;
public int fortunePrice = 25;
public int newAmnt;
public gameObject mainChart;
void payFortune(){
currentCoins = PlayerPrefs.GetInt ("coins");
newAmnt = currentCoins -= fortunePrice;
if(currentCoins >= 25) {
PlayerPrefs.SetInt ("coins", newAmnt);
PlayerPrefs.Save();
mainChart.SendMessage("ask");
}
else {
mainChart.SendMessage("notenough");
}
}
}
Any insights? You guys help would be greatly appreciated!
Comment
Answer by jgodfrey · Mar 11, 2016 at 02:14 AM
I'd say your problem is here:
newAmnt = currentCoins -= fortunePrice;
What are you trying to do there? I doubt that does what you want/expect...
Your answer
Follow this Question
Related Questions
Coin Spending/PlayerPref Subtracting 0 Answers
Playerpref Saving Lag 1 Answer
save a int with playerprefs for one instance of a gameobject 0 Answers