Question by
beaukbacon · Aug 22, 2019 at 06:24 PM ·
c#androidsave datasave file
Creating a binary save file works on windows, but not when I build to android
I have been trying to get an array to save in my game and it only works in the unity editor but when I built to android it didn't work. My code looks like this:
public static void SavePlayer(Player player)
{
BinaryFormatter bf = new BinaryFormatter();
FileStream stream = new FileStream(Application.persistentDataPath +@"/player.fun", FileMode.Create);
PlayerData data = new PlayerData(player);
bf.Serialize(stream, data);
stream.Close();
}
public static int[] LoadPlayer()
{
if (File.Exists(Application.persistentDataPath +@"/player.fun"))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream stream = new FileStream(Application.persistentDataPath +@"/player.fun", FileMode.Open);
PlayerData data = bf.Deserialize(stream) as PlayerData;
stream.Close();
return data.SavedLevelSetup;
}
else
{
Debug.Log("oogaa");
return null;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Save Data Android C# 0 Answers
Android persistentdatapath Can be read but not written. 0 Answers
Save/Load Data Android device , Unity , C# 0 Answers
Screenshot on Android 2 Answers