Files
the-peoples-messenger/Assets/Scripts/GlobalStateManager.cs
T
2026-08-30 01:54:16 +01:00

95 lines
2.1 KiB
C#

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using Utils;
public class GlobalStateManager : Singleton<GlobalStateManager>
{
public int MenuIntended = 0;
public int LevelIntended;
public int HighestLevel;
public List<TextAsset> levels;
public TextAsset parlorPuzzles;
public bool finalScene = false;
//aaaaa theres nicer syntax for this i think
protected override bool dontDestroyOnLoad()
{
return true;
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
HighestLevel = PlayerPrefs.GetInt("HighestLevel", 0);
}
// Update is called once per frame
void Update()
{
}
public void SetLevelCompleted()
{
if (LevelIntended == HighestLevel)
{
LevelIntended++;
HighestLevel++;
PlayerPrefs.SetInt("HighestLevel", HighestLevel);
PlayerPrefs.Save();
if (LevelIntended == levels.Count)
{
//win scene!!!
finalScene = true;
SceneManager.LoadScene(2);
}
else
{
finalScene = false;
//Reload game scene to start next level??
SceneManager.LoadScene(1);
}
}
else
{
//playing old level so load level select
MenuIntended = 1;
SceneManager.LoadScene(0);
}
}
public void PlayNewestLevel()
{
LevelIntended = HighestLevel;
//load game scene
SceneManager.LoadScene(1);
}
public void LoadSpecificLevel(int level)
{
if (level == levels.Count)
{
finalScene = true;
SceneManager.LoadScene(2);
}
else
{
finalScene = false;
LevelIntended = level;
//load game scene
SceneManager.LoadScene(1);
}
}
}