private void SaveBestRunData() { Debug.Log("Saving tunnel runner data"); BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(Application.persistentDataPath + "/exosphereTRData.dat"); TunnelRunnerSaveData dataToBeSaved = new TunnelRunnerSaveData(bestScore, bestDistance, bestCrateCount, bestKmTime); //save data to file bf.Serialize(file, dataToBeSaved); file.Close(); }
private void LoadBestRunData() { if (File.Exists(Application.persistentDataPath + "/exosphereTRData.dat")) { Debug.Log("Loading tunnel runner data"); BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/exosphereTRData.dat", FileMode.Open); //pull data from file TunnelRunnerSaveData savedData = (TunnelRunnerSaveData)bf.Deserialize(file); file.Close(); //read contents into local variables bestScore = savedData.saveScore; bestDistance = savedData.saveDistance; bestCrateCount = savedData.saveCrateCount; bestKmTime = savedData.saveKmTime; } }