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 Jan_Julius · Oct 21, 2014 at 10:06 AM · playerprefssaving

Using playerprefs to remember a level completion

I have a function that gets called whenever a level gets completed:

 public void LevelComplete(){ //code here }

But how can I correctly use playerprefs to remember that I finished the level? there is a variable that contains the number of what level it is in but I don't know if playerprefs has something special that can help me do this a lot easier than what I had in mind.

Thanks,

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by HarshadK · Oct 21, 2014 at 11:44 AM

Since you have a variable that stores the number of level currently on you can do something like:

 int levelNumber;

 void Start () {
     PlayerPrefs.SetBool("Level"+levelNumber.ToString(), true);
     PlayerPrefs.Save();
     PlayerPrefs.GetBool("Level"+levelNumber.ToString());
 }

Get the logic from above code snippet as to how you can set and get a level status using the level number you have.

Now you can set bool to be true if level is complete. And you can even check if the key exists for that level using PlayerPrefs.HasKey and if there is no key then level is not complete. But mind that PlayerPrefs are not at all secure to store level completion. User can very easily cheat.

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 Jan_Julius · Oct 27, 2014 at 09:07 AM 0
Share

Sorry for the late response,

If it's not all that secure what would playerprefs be useful for and what would you recommend me using to store level completion?

avatar image HarshadK · Oct 27, 2014 at 09:19 AM 0
Share

PlayerPrefs is useful for as the name suggests, to save player preferences like player character name or any such detail that is non-essential with respect to cheating, if user decides to cheat. Playerprefs are stored in plain text file that user can open and easily make changes to it. Now consider if player changes name of his player character, it is not gonna provide him with any special way to progress in game.

But if user can easily manipulate the level he has completed then he can proceed to next level easily without completing previous levels. This clearly fails the level unlock mechanism.

One better way is to store them in a binary file. This way it will be hard for user to modify this. At least it won't be easy for user to cheat. To add an extra layer of security you can encrypt the data before storing it in the file. Security of the data is a big field in itself. And the amount of security depends on your requirements and level of security required.

But in your case it would be enough to store them encrypted in a binary file. You can watch how to read write binary file in this training video: Persistence - Saving and Loading Data

avatar image Jan_Julius · Oct 27, 2014 at 10:21 AM 0
Share

Thanks a lot, I've looked at it and yes it does make sense this is a very nice way of saving my data and I will give it a try thanks a lot for your help I will keep the thread open for now because I might have more questions if you don't $$anonymous$$d.

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

27 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Saving with PlayerPrefs? How it works? 1 Answer

Saving and loading game with PlayerPrefs 1 Answer

Having issues with PlayerPrefs... 2 Answers

Save Datasets at runtime 2 Answers

PlayerPrefs not saving after i quiet application 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