/// <summary> /// Load the player data from file /// </summary> public void Load() { if (File.Exists(this.fileString)) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(this.fileString, FileMode.Open); Debug.Log(file.ToString()); SleepwalkerData swdata = (SleepwalkerData)bf.Deserialize(file); this.sleepwalker.setVariables(swdata.health, swdata.score); this.currentLevel = swdata.level; file.Close(); } }
/// <summary> /// Save the player data to file. /// </summary> public void Save() { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(this.fileString); SleepwalkerData swdata = new SleepwalkerData(); swdata.health = this.sleepwalker.GetHealth(); swdata.score = this.sleepwalker.GetScore(); swdata.level = this.currentLevel; bf.Serialize(file, swdata); file.Close(); }