Unity c# save??? | SoloLearn: Learn to code for FREE!


Unity c# save???

How do you save variables in unity c# so next time you open the game it will have saved the stored data from last time inside?

5/6/2020 9:26:44 PM


5 Answers

New Answer


I’m no expert but I’d love to help! :D. Are you talking about any particular variable. And also if you could provide me with the code I might be able to help more. Thanks, Codeize.


See https://docs.unity3d.com/ScriptReference/PlayerPrefs.html RTFM


If you want to store a simple data like a int or float or even a string you could use this Class in unity "PlayerPrefs" . It has some Static Methods like : SetFloat() ,GetFloat() ... -if you want more information read the documentation : https://docs.unity3d.com/ScriptReference/PlayerPrefs.html


Codeize example: float num; if (Input.GetKey(“w”)) //if W is pressed { num += 0.1; } so now i open the game and press w 3 times so the num variable = 0.3 //then it saves somehow i quit the game i run it again num is still = 0.3 idk if this is just a unity c# thing unfortuantly


thank you Martin Taylor and Yahya LAZREK I will check it out later when i have my laptop again thanks again bye