не работает скрипт переключения уровней, проблема в том, что когда я перехожу на 2 уровень, открываются сразу все
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class LevelController : MonoBehaviour
{
public static LevelController instance = null;
int sceneIndex;
int levelComplete;
// Start is called before the first frame update
void Start()
{
if (instance == null)
{
instance = this;
}
sceneIndex = SceneManager.GetActiveScene().buildIndex;
levelComplete = PlayerPrefs.GetInt("LevelComplete");
}
public void IsEndGames()
{
if(sceneIndex == 6)
{
Invoke("LoadMainMenu", 1f);
}
else
{
if (levelComplete < sceneIndex)
PlayerPrefs.SetInt("LevelComplete", sceneIndex);
Invoke("NextLevel", 1f);
}
}
void NextLevel()
{
SceneManager.LoadScene(sceneIndex + 1);
}
void LoadMainMenu()
{
SceneManager.LoadScene("Main");
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NextLevel : MonoBehaviour
{
private void OnTriggerEnter2D(Collider2D collision)
{
LevelController.instance.IsEndGames();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class MainMenu : MonoBehaviour
{
public Button level2B;
public Button level3B;
public Button level4B;
public Button level5B;
int levelComplete;
// Start is called before the first frame update
void Start()
{
levelComplete = PlayerPrefs.GetInt("LevelComplete");
level2B.interactable = false;
level3B.interactable = false;
level4B.interactable = false;
level5B.interactable = false;
switch (levelComplete)
{
case 1:
level2B.interactable = true;
break;
case 2:
level2B.interactable = true;
level3B.interactable = true;
level4B.interactable = true;
level5B.interactable = true;
break;
}
}
public void LoadTo(int level)
{
SceneManager.LoadScene(level);
}
public void Reset()
{
level2B.interactable = false;
level3B.interactable = false;
level4B.interactable = false;
level5B.interactable = false;
PlayerPrefs.DeleteAll();
}
}