- Home /
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.
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
Excuse me, can you explain it more detail ? How can I save bools variable outside the game ?
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
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
thanks, I'll try this. But, can it applied for mobile game ?
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
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.
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; }
Sorry. I was on holiday. I dont know how to help you. I am terribly sorry.
Your answer
![](https://koobas.hobune.stream/wayback/20220613141029im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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