My levels don't unlock.

Scripts:

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

public class ChooseLevelScript : MonoBehaviour
{
    public Button[] levelbuttons;
    
    int SaveLevel;

    void Start()
    {
        int Levelpassed = PlayerPrefs.GetInt("Levelpassed", 1);

        for (int i = 0; i < levelbuttons.Length; i++)
        {
            if(i + 9 > Levelpassed)
            {
                levelbuttons*.interactable = false;*

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

public class FinishTileScript : MonoBehaviour
{
int Levelpassed;
int sceneIndex;
void Start()
{
sceneIndex = SceneManager.GetActiveScene().buildIndex + 1;
Levelpassed = PlayerPrefs.GetInt(“Levelpassed”);
}

void Update()
{

}

public void OnCollisionEnter2D(Collision2D collision)
{
if (PlayerPrefs.GetInt(“Levelpassed”) < sceneIndex)
{
PlayerPrefs.SetInt(“Levelpassed”, sceneIndex);
SceneManager.LoadScene(“LevelSelection”);

}
}

}

My problem is that my levels don’t unlock, And level 1 locks, I don’t know why.
there are 10 levels with 10 buttons, and the buildindex of level 1 is 2.

Why are you adding the +9 in this line: if(i + 9 > Levelpassed) right now you have if Levelpassed is less than 9 level one will lock, if Levelpassed is less than 10 level two will lock. I don’t see anywhere in your code where you set levelbuttons*.interactable = true; so that would be why they don’t get activated. a small note Levelpassed should be levelPassed for proper naming convention.*

So I fixed the problem!

I forgot to put the script on the object! Whoops!