- Home /
When should I save data
Hello, I'm developing an android game and I wrote some code that i learned from unity3d.com to save and load data onto and from a file. And no I'm not using playerPrefs, I'm using FileStream. So my question is, when should I save data to the file?? If i quit my application and start again it doesn't show the saved high score. I tested my code and it does save and load correctly when I press the buttons i used for debugging. I used OnApplicationQuit() so it saves whenever i quit the application, but it didn't work.
Any help?
Answer by Kiwasi · Mar 28, 2015 at 04:18 AM
Generally you save at points where the player has made progress. The exact implementation depends on your game style. Here are some ideas:
Only on exiting the game
Prompt the player to save the game at regular intervals
Between levels or at checkpoints
Every time the player makes some progress, like gaining an achievement or points
Every 15 seconds
Every time the player makes a significant desicion
Answer by JigneshKoradiya · Mar 27, 2015 at 10:00 PM
for example if this is a method called when player get coin
public static int totalcoins;
void Awake()
{
if(playerprefs.haskey("TotalScosePrefs"))
{
totalcoins=playerprefs.getInt("TotalScosePrefs");//so it give you last stored score
}
}
void PlayerGetCoin()
{
totalcoins=totalcoins+1;
playerprefs.setInt("TotalScosePrefs",totalcoins);
playerprefs.save();
}