public void SaveGame() { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(Application.persistentDataPath + "/MySaveData.dat"); SaveSimpleData data = new SaveSimpleData(); data.savedInt = intToSave; data.savedFloat = floatToSave; data.activeLevelConfiguration = activeLevelConfiguration; bf.Serialize(file, data); file.Close(); Debug.Log("Game data saved!"); }
public void LoadGame() { if (File.Exists(Application.persistentDataPath + "/MySaveData.dat")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/MySaveData.dat", FileMode.Open); SaveSimpleData data = (SaveSimpleData)bf.Deserialize(file); file.Close(); intToSave = data.savedInt; floatToSave = data.savedFloat; activeLevelConfiguration = data.activeLevelConfiguration; Debug.Log("Game data loaded!"); } else { Debug.LogError("There is no save data!"); } }