Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by 3 · Mar 03, 2013 at 12:40 AM · iosvariablesavevariablessaving

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,

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DrMrkev · Nov 02, 2015 at 02:45 PM 0
Share

thank you people, I can now save the last played level for continuation :)

sry for my bad english, i am czech.

avatar image DrMrkev · Nov 02, 2015 at 02:45 PM 0
Share

thank you people, I can now save the last played level for continuation :)

sry for my bad english, i am czech.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image 3 · Mar 03, 2013 at 01:03 AM 0
Share

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?

avatar image numberkruncher · Mar 03, 2013 at 01:06 AM 0
Share

Yes you can use PlayerPrefs on both iOS and Android devices.

avatar image 3 · Mar 03, 2013 at 01:09 AM 0
Share

Thanks again, good luck to anyone who reads this.

avatar image HippoMonk 3 · Oct 18, 2015 at 05:01 PM 0
Share

Does this work for all platforms like Consoles and Windows Store?

avatar image
1

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges