我正在制作一个用于在游戏中保存和加载商店的系统。我面临的问题是:
类型' dataToBeSaved'不包含带有' 0'的构造函数参数
问题出现在这一行:datosAguardar datos = new datosAguardar ();
,这是我的代码:
public int puntuacionMaxima = 0;
public static estadoJuego estadojuego;
private string rutaArchivo;
void Awake ()
{
rutaArchivo = Application.persistentDataPath + "/datos.dat";
if (estadojuego == null)
{
estadojuego = this;
DontDestroyOnLoad (gameObject);
} else if (estadojuego != this)
{
Destroy (gameObject);
}
}
// Use this for initialization
void Start ()
{
cargar ();
}
// Update is called once per frame
void Update () {
}
public void guardar ()
{
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Create (rutaArchivo);
datosAguardar datos = new datosAguardar ();
datos.puntuacionMaxima = puntuacionMaxima;
bf.Serialize (file, datos);
file.Close ();
}
void cargar ()
{
if (File.Exists (rutaArchivo))
{
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open (rutaArchivo,FileMode.Open);
datosAguardar datos = (datosAguardar)bf.Deserialize (file);
puntuacionMaxima = datos.puntuacionMaxima;
file.Close ();
} else
{
puntuacionMaxima = 0;
}
}
[Serializable]
class datosAguardar
{
public int puntuacionMaxima ;
public datosAguardar (int puntuacionMaxima)
{
this.puntuacionMaxima = puntuacionMaxima ;
}
}