How can I lock a Level?

Hello, I’m making my first game in Unity, it’s a 2D runner.
I have created some levels and at the end of each level, there’s a box that unlocks the next level and loads it.
But, the problem is, the player can load the locked levels.
What I have done:

  1. Created a button for each level.
  2. Made a lock texture and added it on each level.
  3. When the player finishes say level 1 (hits the box I mentioned above), the next level will be unlocked and lock is no longer active.
    But even if the lock is active, the player can still load the level and I need to prevent this from happening. Any help, please?
    If you can provide explanation too, that’d be great. I’m still very new to Unity. Thanks.
    Level manager script:
    Levels Select scene:
    Link for the tutorial I used for the script: Level Select Map - Unity 2D Platformer Tutorial - Part 29 - YouTube

Simple. If your level is locked, just disable the button, and the player won’t be able to click it. You can do it with this line: button.GetComponent .enabled = false;
If the level is unlocked, do the same, but instead of enabled = false, set it to true.

Hope that solved your question. If not, let me know and I’ll try to help you.

Use Playerprefabs
and set interactable to false
set first one interactable to true;