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 Brianos · Dec 10, 2014 at 02:28 AM · iosplayerprefsupgrading

How to convert iOS game to unity and use the same load/save highscore files?

I'm converting iOS games from xcode c++ to unity c#. This is how I load and save my scores in xcode :-

 void Load()
 {
     NSUserDefaults *m_pPrefs = [NSUserDefaults standardUserDefaults];
     
     int nScore = 0;
     char szName = "Score";
     
     NSString *pName = [[NSString alloc] initWithUTF8String:szName];
     nScore = [m_pPrefs integerForKey:pName];
     [pName release];
 }

How do I convert this code to unity c#, making sure all previous xcode versions of the games don't lose their scores when updating to the new unity versions?

Comment
Add comment
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

2 Replies

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

Answer by SkaredCreations · Dec 12, 2014 at 11:41 AM

If I'm not wrong, PlayerPrefs on Unity iOS is a wrapper around NSUserDefaults, so you should be able to use this in Unity:

 // The second parameter is the default value, if "Score" does not exist
 int nScore = PlayerPrefs.GetInt("Score", 0);

Just try it on your device and see if it's true.

Comment
Add comment · Show 3 · 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 Brianos · Dec 14, 2014 at 02:15 PM 0
Share

Hi. Thanks for the help, but I've got a similar problem with the Android versions. This time there is a filename parameter. Is it possible the convert the following code to Unity C# and still load the old java version settings?

 public static void LoadData()
 {
     SharedPreferences settings = Context.getSharedPreferences("filename", 0);
             
     m_bSounds = settings.getBoolean("Sounds", true);
     m_nCoins = settings.getInt("Coins", 0);
 }

avatar image Brianos · Dec 31, 2014 at 01:31 PM 0
Share

Thanks SkaredCreations

Android Java has a filename as a parameter of their getSharedPreferences function. I cannot find a way to tell unity to get the SharedPreferences from the original file used in a previous Java version of the app?

avatar image SkaredCreations · Jan 01, 2015 at 05:27 PM 0
Share

I don't know much about Android, anyway the current question is about iOS so you should accept my answer if it was successful to you and eventually post another question for the Android part.

avatar image
0

Answer by KNDL · Dec 14, 2014 at 03:02 PM

As SkaredCreations answered, for SharedPreferences use PlayerPrefs. This works for all platforms including iOS and android.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Where do I put PlayerPrefs.SetInt? 1 Answer

If PlayerPrefs.GetFloat("name") don't excist 3 Answers

Best Distance (Record) System on Infinite Runner game 1 Answer

Game/editor stops responding when going to Highscores 0 Answers

PlayerPrefs Player And Enemy Spawn 1 Answer


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