How to make that if level 1 isnt finished, that you cant play level 2

If you reach the finish of level 1, the playerpref: Level1Done will be set to 1. So that number must be constantly updated. If you press the button of level 2, but you havent reached the finish of level 1. Unity won’t load scene level 2.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GoToLevel2 : MonoBehaviour
{ 
    void Update()
    {
        int Kaas = PlayerPrefs.GetInt("Level1Done");
    }


    
    public void GoToLevelTwo()
    {
        if (Kaas == 1);
        {
            SceneManager.LoadScene("Level 2");
            print("hudhunluhdc");
        }
    }
}

Here is a method you could use.

Create a static public int and call it CurrentLevel. Switch the screen to CurrentLevel.

Now, create another one and call it MaxLevel. What we will do is see if your level unlocked is greater than or equal to the MaxLevel (any levels ahead of the level you are on).

using UnityEngine;

public class AllowPlayLevel : MonoBehaviour
{

          static public int MaxLevel;
          static public int CurrentLevel;

          void Update()
          {
                   if(CurrentLevel >= MaxLevel)
                   {
                              // Your code that allows you to go to the level you are trying to get to
                   }
          }

}