Save system not working
im getting a error for data.text please help
save system:
using UnityEngine;
using System.Collections;
using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using UnityEngine.UI;
public class SaveSystem : MonoBehaviour {
public static Text charText;
public static int money;
public static int cakeMultiplier;
public static Text TextMoney;
public static int CakesUpgrades;
public static Text Cakes;
public static int DVDSUpgrades;
public static Text DVDS;
public static int dvdMultiplier;
public static int CDSUpgrades;
public static Text CDS;
public static int cdsMultiplier;
public static int VideoGamesUpgrades;
public static Text VideoGames;
public static int videogamesMultiplier;
public void SaveState()
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath + "/PlayerData.dat");
PlayerData data = new PlayerData();
data.text = UIInputField.charText.text;
data.money = UpgradeCakes.money;
data.cakeMultiplier = UpgradeCakes.cakeMultiplier;
data.TextMoney = UpgradeCakes.TextMoney.text;
data.Cakes = UpgradeCakes.Cakes.text;
data.CakesUpgrades = UpgradeCakes.CakesUpgrades;
data.DVDSUpgrades = UpgradeCakes.DVDSUpgrades;
data.DVDS = UpgradeCakes.DVDS.text;
data.dvdMultiplier = UpgradeCakes.dvdMultiplier;
data.CDSUpgrades = UpgradeCakes.CDSUpgrades;
data.CDS = UpgradeCakes.CDS.text;
data.cdsMultiplier = UpgradeCakes.cdsMultiplier;
data.VideoGamesUpgrades = UpgradeCakes.VideoGamesUpgrades;
data.VideoGames = UpgradeCakes.VideoGames.text;
data.videogamesMultiplier = UpgradeCakes.videogamesMultiplier;
bf.Serialize(file, data);
file.Close();
}
public void LoadState()
{
if(File.Exists(Application.persistentDataPath + "/PlayerData.dat"))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/PlayerData.dat", FileMode.Open);
PlayerData data = (PlayerData) bf.Deserialize(file);
file.Close();
UIInputField.charText.text = data.text;
UpgradeCakes.money = data.money;
UpgradeCakes.cakeMultiplier = data.cakeMultiplier;
UpgradeCakes.TextMoney.text = data.TextMoney;
UpgradeCakes.CakesUpgrades = data.CakesUpgrades;
UpgradeCakes.Cakes.text = data.Cakes;
UpgradeCakes.DVDSUpgrades = data.DVDSUpgrades;
UpgradeCakes.DVDS.text = data.DVDS;
UpgradeCakes.dvdMultiplier = data.dvdMultiplier;
UpgradeCakes.CDSUpgrades = data.CDSUpgrades;
UpgradeCakes.CDS.text = data.CDS;
UpgradeCakes.cdsMultiplier = data.cdsMultiplier;
UpgradeCakes.VideoGamesUpgrades = data.VideoGamesUpgrades;
UpgradeCakes.VideoGames.text = data.VideoGames;
UpgradeCakes.videogamesMultiplier = data.videogamesMultiplier;
}
}
}
[Serializable]
class PlayerData
{
public string charText;
public int money;
public int cakeMultiplier;
public string TextMoney;
public int CakesUpgrades;
public string Cakes;
public int DVDSUpgrades;
public string DVDS;
public int dvdMultiplier;
public int CDSUpgrades;
public string CDS;
public int cdsMultiplier;
public int VideoGamesUpgrades;
public string VideoGames;
public int videogamesMultiplier;
}
Please - do us (and yourself) a favor and at least attempt to provide enough info so that we can assist.
What is the actual error you're receiving?
Where in the above code does the error happen?
You're unlikely to get any assistance if that's all the energy you can bother to put into providing useful information...
Answer by TBruce · Apr 24, 2016 at 11:52 PM
Open your console window so that you can see all the errors and at a minimum copy them (if you do a print screen you will have an image which you will need to save to a file so that you can post it here). As @jgodfrey said you need to include complete error messages when (at run time or compile time) and where they are located (including line numbers - that's why formatting is important).
Your answer
Follow this Question
Related Questions
Using System.Runtime.Serialization.Formatters.Binary for Windows Store Apps 3 Answers
Editor freezing when saving in binary 1 Answer
Do a smaller object type than int exists? 2 Answers
How to add a new data to existing Binary file without erase the previous data? 0 Answers
Convert int to binary 1 Answer