Hi Everyone. I have save system for my game. Script is working on Windows and Editor. But it is not working on Android Build.
This is my save system
using UnityEngine;
using System.Xml.Serialization;
using System.IO;
public class SaveManager : MonoBehaviour
{
public static void SaveGame(GameData data, string savePath)
{
XmlSerializer serializer = new XmlSerializer(data.GetType());
using (StreamWriter writer = new StreamWriter(savePath))
{
serializer.Serialize(writer, data);
}
}
public static GameData LoadGame(string loadPath)
{
if (File.Exists(loadPath))
{
XmlSerializer serializer = new XmlSerializer(typeof(GameData));
StreamReader reader = new StreamReader(loadPath);
GameData gd = serializer.Deserialize(reader) as GameData;
reader.Close();
return gd;
}
else
{
Debug.Log("There is no save file at " + loadPath);
return new GameData();
}
}
I use this code for save game:
SaveManager.SaveGame(data, Application.persistentDataPath + "/save.xml");
This code for load game:
data = SaveManager.LoadGame(Application.persistentDataPath + "/save.xml");