using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; using System; using System.IO; using System.Runtime.Serialization.Formatters.Binary; public class GameController : MonoBehaviour { public bool created = false; public int currentFloor; public int nextFloor = -99; public Text floor; public Scene interStarstage; public GameController instance; public List Scenes = new List(); public int NextLevel; public int firstLevel = 4; void Awake() { Application.targetFrameRate = 60; if (instance != null) { Destroy(gameObject); } else { instance = this; DontDestroyOnLoad(gameObject); } } // Use this for initialization void Start() { StartCoroutine(ListScenePopulator()); if (File.Exists(Application.persistentDataPath + "/ThePit.sav")) { Load(); } else { NextLevel = firstLevel; } } // Update is called once per frame void Update () { currentFloor = nextFloor; //Return the current Active Scene in order to get the current Scene's name interStarstage = SceneManager.GetActiveScene(); //Check if the current Active Scene's name is your first Scene if (interStarstage.name == "InterStage") { } } public void LoadScene() { SceneManager.LoadScene(NextLevel, LoadSceneMode.Single); } IEnumerator ListScenePopulator() { for (int i = 0; i < SceneManager.sceneCountInBuildSettings; ++i) { string name = System.IO.Path.GetFileNameWithoutExtension(SceneUtility.GetScenePathByBuildIndex(i)); Scenes.Add(name); } yield return Scenes; } public void Save() { BinaryFormatter bf = new BinaryFormatter(); FileStream dataFile = File.Open(Application.persistentDataPath + "/ThePit.sav", FileMode.OpenOrCreate); StoredData sd = new StoredData(); sd.NextLevel = NextLevel; bf.Serialize(dataFile, sd); dataFile.Close(); } public void Load() { BinaryFormatter bf = new BinaryFormatter(); FileStream dataFile = File.Open(Application.persistentDataPath + "/ThePit.sav", FileMode.OpenOrCreate); StoredData sd = (StoredData)bf.Deserialize(dataFile); NextLevel = sd.NextLevel; dataFile.Close(); } public void Delete() { if (File.Exists(Application.persistentDataPath + "/ThePit.sav")) { File.Delete(Application.persistentDataPath + "/ThePit.sav"); } SceneManager.LoadScene(firstLevel, LoadSceneMode.Single); } } [Serializable] class StoredData { public int NextLevel; }