- Home /
iphone PlayerPrefs
hi im making a game for the iphone and i have a problem saving the game when the application is closed. i use a gameObject at the first scene that doesnt destroy on load so it goes through all the scenes. Heres my script i dont know what im doing wrong here!! (im trying with just 1 static var to test it)
"money.moneyT" is the static var that i want to save and retrieve when starting the game again.
function Awake(){
DontDestroyOnLoad(this);
}
function Saving(){
PlayerPrefs.SetInt("money", money.moneyT);
}
function Loading(){
PlayerPrefs.GetInt("money");
}
function Start(){
Loading();
}
function OnApplicationQuit(){
Saving();
}
Please format your code! If you don't know how, watch the video on how to use Unity Answers here: http://video.unity3d.com/video/7720450/tutorials-using-unity-answers
Answer by gregmax17 · Jul 05, 2011 at 10:04 PM
I tried using PlayerPrefs before on the iPhone, but nothing would ever save. I found this by PreviewLabs, and haven't had a problem since. Might help you?
thx gregmax17, but i still dont get anything saved, i did all the steps that previewlabs said to make it work for javascript.I came out with this script and i still dont see what im doing wrong!!! i dont get any errors i dont know if its the function i use or the order that the functions process...( i mean saving before loading or things like that) or should i have playerspref set to all the script that my static var are in ins$$anonymous$$d of using a single gameObject to save all the vars i need...
import PreviewLabs.PlayerPrefs;
function Awake(){ DontDestroyOnLoad(this); }
function Saving(){
PreviewLabs.PlayerPrefs.SetInt("money", money.moneyT);
}
function Loading(){
PreviewLabs.PlayerPrefs.GetInt("money");
}
function Start(){
Loading();
}
function OnApplicationQuit(){
Saving();
}
Answer by feak1 · Jul 06, 2011 at 07:45 PM
i did and still nothing :( whats is wrong i cant figured it out
Answer by Van Zeng · Nov 14, 2012 at 09:01 AM
function Saving(){
PlayerPrefs.SetInt("money", money.moneyT);
PlayerPrefs.Save();
}
Your answer
Follow this Question
Related Questions
PlayerPrefs Int to Float 1 Answer
How to save text and display using Touch Screen Keyboard 1 Answer
playerprefs problem 0 Answers
Playerprefs save player position 3 Answers