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.