//! Handles saving world and exiting to the main menu. public static IEnumerator Save() { float f = 0; while (f < 6000) { f++; if (GameObject.Find("GameManager").GetComponent <GameManager>().blocksCombined == false) { if (GameObject.Find("GameManager").GetComponent <GameManager>().dataSaveRequested == false) { if (GameObject.Find("GameManager").GetComponent <StateManager>().saving == false) { Debug.Log("Game saved to " + FileBasedPrefs.GetSaveFilePath()); Debug.Log("Creating backup..."); string fileName = GameObject.Find("GameManager").GetComponent <StateManager>().worldName; string destinationPath = Path.Combine(Application.persistentDataPath, "SaveData/" + fileName + ".bak"); File.Copy(FileBasedPrefs.GetSaveFilePath(), destinationPath, true); Debug.Log("Backup saved to " + destinationPath); if (GameObject.Find("Player").GetComponent <PlayerController>().exiting == true) { Debug.Log("Loading main menu..."); FileBasedPrefs.initialized = false; FileBasedPrefs._latestData = null; SceneManager.LoadScene(0); } else { break; } } } } yield return(new WaitForSeconds(0.1f)); } }