/// <summary> /// This function saves the current amount of money you have into the save file. /// </summary> public void SaveWalletData() { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(Application.persistentDataPath + SAVEPATH); CurrencyProgress data = new CurrencyProgress(); data.currentWalletContent = currentWalletContent; data.walletSize = currentWalletSize; bf.Serialize(file, data); file.Close(); }
/// <summary> /// This function loads the last saved data you have into the game. /// </summary> public void LoadWalletData() { if (File.Exists(Application.persistentDataPath + SAVEPATH)) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + SAVEPATH, FileMode.Open); CurrencyProgress data = (CurrencyProgress)bf.Deserialize(file); file.Close(); currentWalletContent = data.currentWalletContent; currentWalletSize = data.walletSize; walletSize = walletSizes[currentWalletSize]; } else { currentWalletContent = 0; walletSize = walletSizes[0]; } }