how to make a Level lock/unlock system

how do you make a way so say if you have 10 levels. only one is unlocked then you have to complete level1 to unlock level2. and will save in the Build

for the Campain Mode for my FPS game

You probably just want to create simple booleans for each level, not rebuild each stage…

this is in javascript because I don’t know c

//when you beat the first level assign a variable like leveloncompleted to true
         unlocklevel2 = true;
// do the same for the other levels, level 3 and so on
         unlocklevel3 = true;

//and then on your select level screen when they select a level, make sure 
//that the corresponding level unlock is set to true

if(chosenlevel == level 3 && unlocklevel3 == true){

using a script a lot like this, you should be able to implement level unlocking :slight_smile:

Quishtay™ all the way!

step1: take a bool if only lock and unlock if there is rating system I take string
public static string initGameLevelLocks=“099999999999999999999999999999”;
//0-unlock, 9-locked, 1-One star, 2-two star, 3-three star

(suppose your scenes r menu_scene,level_1_scene …level_n_scene)
step2: write down values in a file in menu_scene when the game first run

public static void CreateFile(string path, string fileName){

public static void WriteFile(string path,string fileName,string data){
StreamWriter sw = new StreamWriter(path+“/”+fileName);

public static string ReadFile(string path,string fileName){
string output=“”;
StreamReader sr = new StreamReader(path+“/”+fileName);
return output;

public static string GetAppDataPathIOS(){
	string path=Application.dataPath.Substring(0,Application.dataPath.Length-5);	
	return path+"/Documents";

public static string GetAppDataPathAndroid(){
	return Application.persistentDataPath;

step3: since the first level is unlock user can play level_1_scene after completing the first level override the value of initGameLevelLocks[0]=star_number; and initGameLevelLocks[1]=‘0’;

private string GetLevelsString(string levels,int level,int rat){
	char[] chars=levels.ToCharArray();
	int currentRat=chars[level-1]-'0';
		return new string(chars);
	char dig = (char)(((int)'0')+rat);
		return new string(chars);
			char d = (char)(((int)'0')+0);
	return new string(chars);

[suppose user now go back to menu_scene]

step 4: since use get 3_star in first level and in initGameLevelLocks[1]==0 so you can unlock the level 2

public static string LevelStatus=FileIO.ReadFile(path,FILE_NAME_LEVELS);

	int _levelStatus=MainMenuScene.LevelStatus[2]-'0';
		sprite.spriteName =Constants.spriteNameLock;
	}else if(_levelStatus==3){ // got 3 star
		sprite.spriteName =Constants.spriteName3Star;
	}else if(_levelStatus==2){ // got 2 star
		sprite.spriteName =Constants.spriteName2Star;
	}else if(_levelStatus==1){ // got 1 star
		sprite.spriteName =Constants.spriteName1Star;
	}else { //simply unlocked
		sprite.spriteName =Constants.spriteName0Star;

finally when click to play an leve
void OnClickLevel(){



//good luck

This line gets the Playerpref string setting from your harddrive and can be assigned to anything, like Application.LoadLoad(LevelToPlay);

var LevelToPlay = PlayerPrefs.GetString("Level");

But if you just finished a level, then you do this :

PlayerPrefs.SetString("Level", Application.loadedLevel);

Application.loadedLevel is the name of the level, so once you finish a level, or start a new level, you can then run that line and it will overwrite with the previous setting.