I need to be able to have a level selection screen with level locking once you reach a certain level.

Hello! My game need a way to unlock a button in a level after reaching a level so here is an example.

So my game uses a weird way to load stuff. When you complete a level it loads a level complete level. i need a way to make is so that when you reach that level it activates a script in the main menu then will let me click on the level select buttons one level ahead of the level that you completed.

the reason there is no script is because i have no clue at all how to make this happen.
an attempt at my level of knowledge would be a waste of time because i can barely code simple scripts and i have no idea where to start such a thing.

javascript would be nice since all of my level loading is done in javascript but c# is also good.
if anyone could help me i would greatly appreciate it.

thanks everybody cheers!

Try this. Its simple but it might work.

But first, i dont know how you want to check
If you actually completed the level.
(Do you exit through a door?)

Im just gonna assume were gonna use a trigger collider
To check if the level is ended.

First, make 3 custom tags. (You can make as many as you like)

Name them

“Level1”

“Level2”

Etc.

Next create a script, call it levelLoading, then paste this.

(Im using c# btw)

using UnityEngine;
using System.Collections;

public class Levels : MonoBehaviour
{
static bool level1done = false;
static bool level2done = false;
static bool level3done = false;

public GUITexture button1;
public GUITexture button2;
public GUITexture button3;

void Start()
{
button1.gameObject.SetActive(false);
button2.gameObject.SetActive(false);
button3.gameObject.SetActive(false);
}

void Update ()
{
DontDestroyOnLoad(this);

if (level1done)
{
Application.LoadLevel("levelSelect");
button1.gameObject.SetActive(true);
button2.gameObject.SetActive(true);
if (button1.HitTest(Input.mousePosition))
{
Application.LoadLevel("Level1");
}
if (button2.HitTest(Input.mousePosition))
{
Application.LoadLevel("Level2");
}
}

if (level2done)
{
Application.LoadLevel("levelSelect");
button3.gameObject.SetActive(true);
if (button3.HitTest(Input.mousePosition))
{
Application.LoadLevel("Level3");
}
}

if (level3done)
{
Application.LoadLevel("levelSelect");
Debug.Log("you won :D");
}
}

void OnTriggerEnter(Collider other)
{
if (other.transform.tag == "Level1")
{
level1done = true;
}
if (other.transform.tag == "Level2")
{
level2done = true;
}
if (other.transform.tag == "Level3")
{
level3done = true;
}
}
}

Also remember to create 3 gui texture objects in your scene and assign them to the script.

Also attach this script to any object in your scene and create 3 box colliders, one for each level, and assign those custom tags to them one by one. (Dont forget to mark them as ‘trigger’)!

For anyone still looking for other ways of doing this.

//Put this as a funtion in your "Level Win" funtion.
nextLevelLoad = (SceneManager.GetActiveScene().buildIndex + 1);
if (nextLevelLoad>PlayerPrefs.GetInt("levelAt"))
        {
            PlayerPrefs.SetInt("levelAt",nextLevelLoad);
            print(PlayerPrefs.GetInt("levelAt"));
        }

//Then put this in the start funtion of your Level Select
private void Start()
    {
        int levelAt = PlayerPrefs.GetInt("levelAt", 2);

        for (int i = 0; i < lvlButtons.Length; i++)
        {
            if (i+2>levelAt)  //The plus 2 takes into account that you have 2 scenes before your 
                {            //first level, a main menu and a level select. Adjust if needed.
                    lvlButtons*.interactable = false;*

lvlButtons*.gameObject.SetActive(false);*
}
}
}
Attach this funtion in the second script to a game object in your level select then put each level in the right place via the inspector.
All props to this youtube vid.
_*Unity 2022 Tutorial: SIMPLE Level Selection (Locking & Unlocking Levels) - YouTube