• 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 BraveVN · Mar 24, 2014 at 08:24 AM · lockunlock

Problem about Lock/ Unlock level

I use some boolean variables to make a Lock/ Unlock level system. But if I unlock all level and quit game, then play again, all levels are locked like before. How can I fix it ?

Thanks, I'm not a native English.

Comment
Add comment · Show 6
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 ShadoX · Mar 24, 2014 at 08:25 AM 1
Share

You have to save those bools somewhere outside of the game, like some save file and when you start up the game again it would read the file and set the bool values according to what you have in the file

avatar image BraveVN · Mar 24, 2014 at 08:44 AM 0
Share

Excuse me, can you explain it more detail ? How can I save bools variable outside the game ?

avatar image le_duke · Mar 24, 2014 at 08:53 AM 0
Share

He mean saving the game state in a database or in a file before you quit the game. And then when the user start the game you load the file and check what levels are unlocked

avatar image LudwigVK · Mar 24, 2014 at 09:03 AM 2
Share

You can use the function PlayerPrefs, it is pretty easy! give it a try... Basically, you can save or load whatever floats, strings or int's you want into a default file that UnityEngine creates on the host computer.

http://docs.unity3d.com/Documentation/ScriptReference/PlayerPrefs.html

avatar image BraveVN · Mar 24, 2014 at 09:57 AM 0
Share

thanks, I'll try this. But, can it applied for mobile game ?

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by GluedBrain · Sep 22, 2014 at 09:59 AM

As mentioned by other users here, you can either use PlayerPrefs or you can go for Serialization. Check out the article from TheGameContriver on this topic

Unity Lock Unlock System - TGC

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

Answer by RuanBrummer · Nov 24, 2021 at 08:10 AM

you just need to save the game. I saw brackeys made a video on binary save. I hope this helps.

Comment
Add comment · Show 2 · 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 italhaali88 · Nov 24, 2021 at 08:57 AM 0
Share

Well, I saw it, but i am using playerprefs and issue is when i complete 6 levels or 7 or more, and then i click the level 3 and win that and go back to game only first 4 are showing active,

here is code

int levellock = PlayerPrefs.GetInt("levellock"); for(int i = 0; i < levellockunlock.Length; i++) { levellockunlock[i].interactable = false; } for(int i = 0; i < levellock; i++) {
levellockunlock[i].interactable = true; // currentlevel = levellock+1; }

avatar image RuanBrummer · Dec 12, 2021 at 07:16 PM 0
Share

Sorry. I was on holiday. I dont know how to help you. I am terribly sorry.

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

26 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

Related Questions

How do I enable the Android lock screen in developer mode? 1 Answer

Locking and Unlocking a cursor... 2 Answers

PlayerPrefs Problem crashing with SetBool 2 Answers

What's the function of the little lock icon on the Project Browser? 1 Answer

Configurable joint lock and unlock rotations by code. 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