- Home /
How to store a variable after quit? (iOS)
Well basically, I want a variable that would allow me to save things. Now when you quit the game, the game essentially resets. Is there some simple way, so that if I wanted the player to have something unlocked, I could just put:
var silencer == true;
and keep it even after they quit? I've made a few games in Unity and have 10s of hours of experience, but I never figured this one out. I've heard of player prefs, but if there was a simpler way of saving a variable or anything else it would be great. thanks, and I've heard of Static Variables. simply putting static var
right? I not sure what static variables do, but does it save it after a quit?
Thanks again,
thank you people, I can now save the last played level for continuation :)
sry for my bad english, i am czech.
thank you people, I can now save the last played level for continuation :)
sry for my bad english, i am czech.
Answer by numberkruncher · Mar 03, 2013 at 12:50 AM
A static
variable is one that is declared in a global scope so that it can be accessed without a class instance. Whereas a member variable is one that is defined within the scope of an object instance.
In any case, static
will not persist the value of the variable after leaving your game. Instead you should consider using the player preferences class for simple variables like this:
// Use 1 for true and 0 for false
PlayerPrefs.SetInt("inventory.silencer", silencer ? 1 : 0);
Also see: http://docs.unity3d.com/Documentation/ScriptReference/PlayerPrefs.html
Both answers helped me out, but you answered first and they were both pretty similar. Thanks, By the way does playerprefs work on iOS and Android?
Yes you can use PlayerPrefs
on both iOS and Android devices.
Does this work for all platforms like Consoles and Windows Store?
Answer by $$anonymous$$ · Mar 03, 2013 at 12:52 AM
you can use player prefs here is a documentation. Btw static vars no not change so they use up less resources and can be easier accessed globally
Your answer
Follow this Question
Related Questions
How to save a gameObjects on a prefab and variables with a script? 1 Answer
How do you copy PersistentDataFolder between devices? 2 Answers
[iOS]UnauthorizedAccessException: Access to path error 0 Answers
Changing a public varible from another script 3 Answers
How do i imports my variable to another variable and save it with PlayerPrefs? 0 Answers