I am trying to save data and load data on the project i am working on, but i cant seem to get it work in an Android device it works fine on Unity when i play it, not sure what i am missing or done wrong here is the following code i use to save and load data.
using System.Collections; using System; using System.Runtime.Serialization.Formatters.Binary; using System.IO;
public class PlayerInfo : MonoBehaviour {
public static PlayerInfo playerData;
public int gameCoins;
void OnDisable()
{
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Create (Application.persistentDataPath + "playerinfo.dat");
PlayerData data = new PlayerData ();
data.gameCoins = gameCoins;
bf.Serialize (file, data);
file.Close ();
}
void OnEnable()
{
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open (Application.persistentDataPath + "playerinfo.dat", FileMode.Open);
PlayerData data = (PlayerData)bf.Deserialize (file);
file.Close ();
gameCoins = data.gameCoins;
}
}
[Serializable]
class PlayerData
{
public int gameCoins;
}
Anyone can give me an idea of what i need to do or look at i will be very much appreciated, and many thanks in advance for taking the time to help.
Application.persistentDataPath + "/playerinfo.dat"
\$\endgroup\$