- Home /
How to script a Save/Load option on IPhone?
Hi! I was doing some research, but I couldn`t find a simple way for recording some information in IPhone. I want do know how save simple data, like de PlayerPrefs, but without loosing them after the program is closed. I want basically save the options of the player and also the local scoreboard of the game. I would really appreciate any help, thx!
-------- EDITED ---------
Like my friend there told me, PlayerPrefs should me saving the variables even when the game is turned off. So now my problem becomes the follow: " Why am I loosing de PlayerPrefs just when my game is closed "? This is where a think the problem is:
function Start(){
if ( !PlayerPrefs.HasKey("level") ){
PlayerPrefs.SetInt("level", 2);
PlayerPrefs.SetInt("sound", 1);
PlayerPrefs.SetInt("music", 1);
PlayerPrefs.SetInt("skin", 1);
}
iPhoneSettings.screenOrientation = iPhoneScreenOrientation.Landscape;
}
This is the code executed in my menu screen. I check if the level have already been set, if not ( meaning that this is the first time that the game is running ) I put the values of the PlayerPrefs to the default ones. I'm doing it right? Just remember that if a go to the menu screen during the game, the PlayPrefs continue normal. But if I quit, they come back to the default ones...
Answer by duck · Oct 10, 2010 at 01:30 PM
The data stored usingPlayerprefs should not be lost after the program is closed, so it's ideal for your needs.
No, you are wrong. The PlayerPrefs are lost after closing the game. $$anonymous$$aybe you are getting confused because when you pause the application, you don't lose the PlayerPrefs, but you can see under the applications that are still running ( double press the IPhone button ) that the game is still there. You can quit the game by holding the finger on the applicantions that are running and them pressing the red button, or turning off the IPhone.
Actually, its right. Something must be wrong with your implementation. In my game, closing out of the unity app as you describe and forcing a complete restart does keep the player prefs that I've saved.
Yes man, you are absolutely right! Sorry if I was rude. But my problem persists... Thanks for the help anyway!
$$anonymous$$aybe you could edit your question to include the code you're using to save your data, so we could see if there are any problems with it.
Oh, you did. The code looks okay. Now post the code where you read the values back out!
Your answer
Follow this Question
Related Questions
player prefs, problem but no problem??? 1 Answer
Load XML File ? 1 Answer
Save variable value. 1 Answer
Saving data 1 Answer