I have a game with unlockable levels, and at lets say Level 3, when i win level 2, the level 3 button is unlocked. But when i go to main menu from pausing Level 3, all the buttons reset. Here is the code:
Level menu code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class LevelSelection : MonoBehaviour
{
public Button lvlButtons;
// Start is called before the first frame update
void Awake()
{
int levelAt = PlayerPrefs.GetInt("levelAt", 2);
for (int i = 0; i < lvlButtons.Length; i++)
{
if (i + 2 > levelAt)
lvlButtons*.interactable = false;*
}
}
}
Next level code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MoveToNextLevel : MonoBehaviour
{
public int nextSceneLoad;
// Start is called before the first frame update
void Start()
{
nextSceneLoad = SceneManager.GetActiveScene().buildIndex + 1;
}
public void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == “covek”)
{
if (nextSceneLoad > PlayerPrefs.GetInt(“levelAt”))
{
PlayerPrefs.SetInt(“levelAt”, nextSceneLoad);
}
}
}
public void Leveli()
{
SceneManager.LoadScene(nextSceneLoad);
}
}
Main menu code (for both buttons)
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using System.Collections;
public class levelmenu : MonoBehaviour
{
public void levelmeni()
{
SceneManager.LoadScene(“Level Selections”);
}
}