In this code, I click on button for level 1, and I play out level 1. Once I return back to the map, level 2 should be unlocked because I set the boolean to true when I pressed button 1.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MainButtons : MonoBehaviour
{
private bool level2Ready;
private bool level3Ready;
private bool level4Ready;
private bool level5Ready;
void Start()
{
level2Ready = false;
level3Ready = false;
level4Ready = false;
level5Ready = false;
}
public void Level1Map() { //button 1 in the map is pressed
level2Ready = !level2Ready; // unlocks level 2 button
SceneManager.LoadScene(0);
}
public void Level2Map() { // level 2 button is pressed
if (level2Ready == true) {
SceneManager.LoadScene(4); //loads level 2 game scene
level3Ready = true;
}
}