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

+1

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

DevHaz

5 Answers

New Answer

+3

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.

+3

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

+2

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

+1

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

+1

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