Persist data

Hi, I have score and time into a UserStats class. I load the first level and I save the data into these variables. But when I load the next level I lost them. Because the new level instantiate the UserStats again. What is the right way to persist these variables during the game? Thanks.

Hi alexandros356

If you want to use these variables during the current session, you can use static variables. Use them with caution, they can flood your memory.
See “Global variables” in:
http://docs.unity3d.com/Documentation/ScriptReference/index.Member_Variables_26_Global_Variables.html

But another point of view is when you want something to be kept in memory forever (eg. high scores). Then you would want to use PlayerPrefs to get and set those variables. See:

and

Thanks Jlu!