public static void SavePlayer(ScoringSystem player) { BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + "/player.dat"; FileStream stream = new FileStream(path, FileMode.Create); PLRData data = new PLRData(player); formatter.Serialize(stream, data); stream.Close(); Debug.Log("Game Saved" + data); }
public void LoadPlayer() { PLRData data = SaveSystem.LoadPlayer(); theGameScore = data.score; numberOfAliensFound = data.aliensFound; currentScene = data.activeScene; tutorialDialogDone = data.tutorial; pointsCount.text = theGameScore.ToString(); aliensCount.text = numberOfAliensFound.ToString(); theScore = theGameScore; numberOfAliens = numberOfAliensFound; Debug.Log("Loaded from " + theScore); Debug.Log("Loaded from " + numberOfAliens); SceneManager.LoadScene(currentScene); }
public static PLRData LoadPlayer() { string path = Application.persistentDataPath + "/player.dat"; if (File.Exists(path)) { BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Open); PLRData data = formatter.Deserialize(stream) as PLRData; stream.Close(); Debug.Log("Game Loaded"); return(data); } else { Debug.LogError("Save file not found in " + path); return(null); } }