Question by
DroidifyDevs · Mar 06, 2016 at 11:42 PM ·
c#scripting problemplayerprefsaddsubtract
How to do + or - functions to PlayerPrefs.SetInt?
So I've been trying to remove 25 from PlayerPrefs like this
PlayerPrefs.SetInt("removehere", -25);
I know for a regular int I could do this:
removehere -= 25;
But that isn't working for PlayerPrefs. How do I reduce the int value of a PlayPref by 25? Thanks!
Comment
Best Answer
Answer by jgodfrey · Mar 07, 2016 at 02:10 AM
Do you simply want to reduce the stored value, without actually using it? If you think about it in a couple of steps, you have this:
int val = PlayerPrefs.GetInt("SomePref"); // load the current value
val -= 25; // subtract 25 from the value
PlayerPrefs.SetInt("SomePref", val); // store the new value
If you want to do it in a single step, without actually having intermediate access to the value, you could do something like:
PlayerPrefs.SetInt("SomePref", PlayerPrefs.GetInt("SomePref") - 25);
Thought, I'm not sure why you'd want to do that...
Hi, I know I kindo of late, but it didn’t work for me... is there another way??