Search Unity

Unity Level Unlocking System Using PlayerPrefs

Discussion in 'iOS and tvOS' started by JamesArndt, Aug 10, 2012.

  1. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    Finished up this simple tutorial demoing a system similar to what I use in my iOS projects. Wanted to share the knowledge.

     
  2. Default117

    Default117

    Joined:
    Mar 13, 2011
    Posts:
    134
    Very nice James =] I've yet to have the need for something like this, but it will come up soon, good to affirm your ideas are similar to what i would have thought to do. The only thing i would look into differently is the actual saving of wether or not levels have been unlocked. I would have thought that PlayerPrefs might not have been the best solution for something like this? First reason being if the app is uninstalled/reinstalled the playerprefs are cleared, and secondly its non transferable between devices.
    Great tutorial for someone getting into the logic of it though!
     
  3. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    Yeah that's another tutorial coming...something like data saved server-side might be ideal.
     
  4. Default117

    Default117

    Joined:
    Mar 13, 2011
    Posts:
    134
    Sweet. Something I was going to try and check out was saving to the iCloud.
     
  5. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    I wonder if I could send save data to something like a secure Dropbox (one I host)? You've just got me thinking about other ideas with this.
     
  6. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    Be careful with saving important data in PlayerPrefs. It is dead simple to modify the file even with a non-jailbroken device. It doesn't matter so much if it isn't in app purchase content you are protecting but if the user is paying you will definitely want to make it harder to unlock paid content than simply modifying a single value in a file.
     
  7. AngryOrange

    AngryOrange

    Joined:
    Jan 30, 2012
    Posts:
    103
    So in your opinion which method is the best to unlock levels on iOs devices ?
     
  8. Phil-AV

    Phil-AV

    Joined:
    Jul 9, 2012
    Posts:
    57
    On the subject of users modifying playerprefs - I doubt it's too much of a problem. The reasoning is that a typical iOS user will not know how to go about doing this, a fair few might and wont anyway, and those that will would probably go to greater lengths than modifying the playerprefs to get the unlocks.

    A tiny bit of obfuscation can go a long way. Scrambling keys and values in the playerprefs is usually enough of a deterrent with very little effort, and any further client-side protection probably wont be worth the hassle for the very small amount of gain.

    (Totally modifying/re-writing sections of my in-app code as I type this!)

    [Edit: Sensitive information is a different matter - pay very careful attention with users' personal/sensitive data.]
     
  9. 3dgrinder

    3dgrinder

    Joined:
    Oct 21, 2008
    Posts:
    249
    Prime31 is right! Don't save anything related IAP or major gameplay in there. You can use your local file system with encryption. But unity should provide another function like

    PlayerPrefs.SetEncryptionKey( string key );

    something like this. That will help a lot for simple purpose.
     
  10. Tanapat

    Tanapat

    Joined:
    Jan 11, 2013
    Posts:
    2
    Thank You
     
  11. Tanapat

    Tanapat

    Joined:
    Jan 11, 2013
    Posts:
    2
    i want to unlock all map and charactor when player collect all of item and tell player what charactor and map are unlocked before game start

    Thank You ^^
     
  12. ishtiaqwajid

    ishtiaqwajid

    Joined:
    Oct 16, 2019
    Posts:
    4
    But if we play Level 1 after level 3 there will appear lock agai on level 3 which is not look good
     
  13. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    I'm amazed this works at all. Unity no longer supports this scripting language. I'm thinking of redoing this tutorial again with C# and keeping it up to date.