- Home /
levels unlocking system
I am making my first game ever a really simple one but it has some levels the problem is I know how to make a level selection system but does anyone know how to make it so you're only able to select the level after completeion?
Answer by galsein · Jul 18, 2016 at 04:56 AM
You can create a boolean list / boolean array. (To store if a level is opened or not)
public List<bool> unlocked;
public List<GameObject> LevelButton;
Every time you finish a level, set the unlock of the next level to true
public void Unlock(int level)
{
unlocked[level] = true;
}
When you display the unlocked level list, you can always check the bool before enabling the button / entering the level
public void EnterLevel(int level)
{
if (unlocked[level] == true)
{
//enter level
}
}
If you're disabling the buttons, set the GameObject LevelButton to respective buttons that leads the player to the Levels. Level 1 Button sould be LevelButton[0], etc. and call this class when you go to the level selection.
public void updateButtons()
{
for (i=0; i<numberoflevels ; i++)
{
if(unlock[i] ==false)
{
LevelButton[i].GetComponent<Button>.enabled = false;
}
else
{
LevelButton[i].GetComponent<Button>.enabled = true;
}
}
}
okay thanks galsein this helps a lot I think I'm starting to understand what a bool is
Answer by Padalino · Jul 18, 2016 at 12:10 PM
You can use a boolean variable. For example public bool level1Completed = false
in a, for example, levelTrackerScript Then in your 'game manager' or so, after doing that event that finishes the level, add this: levelTrackerScript level1 = GameObject.FindGameObjectWithTag("WhateverTag").GetComponent<YourManagerScript> (); level1.level1Completed = true;
Then, in your levelTrackerScript use that boolean to unlock the level. For example, enabling a button that now you can click: if(level1Completed == true){ myButton.enabled = true; //this way it appears on the screen, but you can't click it, or myButton.gameObject.SetActive (true); //it only appears if you completed the level }
Remember to add the levelTrackerScript to an empty GameObject, and add this line of code inside the Start funcion DontDestroyOnLoad(this)
very important to keep tracking levels.
Hope this solved your question.
thans for the comment I have yet to look into booleans e.t.c. so I'll look into it and hope for the best
Answer by Gaming-Dudester · Jul 18, 2016 at 03:04 AM
Would you not just make a bool and set it to true after the level is completed? And if the bool is true then you can select the level! And create bools for each of the levels? Or make a number and add 1 to each time you complete a new level and then whatever the number equals then you can access the level up to that number. Am I misunderstanding? Sorry if so. If not then GR8! ^_^
Your answer
Follow this Question
Related Questions
Level select screen unlock on completion of game 2 Answers
Purchase Level Unlock System 1 Answer
Problems with unlocking levels 1 Answer
Key to use to unlock a teleporter 1 Answer
Level Unlock system 0 Answers