Próbuje serializować dane ale wyskakują mi błędy
Assets\Scripts\saveScript.cs(19,20): error CS0246: The type or namespace name 'Save' could not be found (are you missing a using directive or an assembly reference?)
w 3 liniach 19, 37 i 42 czyli wszędzie gdzie występuje save.
to mój kod:
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine;
[RequireComponent(typeof(GameData))]
public class saveScript : MonoBehaviour
{
private GameData gameData;
private string savePath;
void Start()
{
gameData = GetComponent<GameData>();
savePath = Application.persistentDataPath + "/gamesave.ok";
}
public void SaveData()
{
var save = new Save()
{
SavedInteger = gameData.GameInteger
};
var binaryFormatter = new BinaryFormatter();
using (var fileStream = File.Create(savePath))
{
binaryFormatter.Serialize(fileStream, save);
}
Debug.Log("Data Saved");
}
public void LoadData()
{
if (File.Exists(savePath))
{
Save save;
var binaryFormatter = new BinaryFormatter();
using (var fileStream = File.Open(savePath, FileMode.Open))
{
save = (Save)binaryFormatter.Deserialize(fileStream);
}
gameData.GameInteger = save.SavedInteger;
gameData.ShowData();
Debug.Log("Data Loaded");
}
else
{
Debug.LogWarning("Save file doesn't exist.");
}
}
}