- Home /
Why do my variables not get changed?
Hello guys. I know (thanks to Debug.Log) that my code does get executed. Also i don't get any errors in console. But my Problem is, that in the end all variables in the PlayerPrefs stay 0. Does anyone have an idea why this might happen?
make i single simple script to test one value of player prefs without loading new scene ata the end, do debug it step by step
Is it the actual variables that aren't being modified when this behavior is invoked or is is that the PlayerPrefs aren't being updated? PlayerPrefs is not a very stable place to store stuff. I've had to call a method (PlayerPrefs.Save) to make sure they actually get saved and then, of course, all those data live at the mercy of the platform on which your game is running.
Answer by ooblii · Aug 29, 2017 at 02:10 PM
Your code doesn't show the value of any of your "Wert" modifiers. So if I had to guess, they're all set to 0. thus multiplying your constants by 0 and then adding 0 to the original variable.
I tried it with numbers ins$$anonymous$$d of the modifiers and still got the same result. Therefore this shouldnt be the isue.
Not sure then. This works as expected:
float eisen = PlayerPrefs.GetFloat("eisen", 2.2344f);
Debug.Log(eisen);
eisen += 1000 * 2f;
PlayerPrefs.SetFloat("eisen", eisen);
Debug.Log(PlayerPrefs.GetFloat("eisen"));
Your answer
![](https://koobas.hobune.stream/wayback/20220612133804im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Running a script without being attached to an object? 2 Answers
How to define a slider on script file? 1 Answer
Running animation not working and jumping isn't working. 0 Answers