- Home /
HELP saving/loading game! please!
So I need to know how to write a script for saving/loading, I would really appreciate it if somebody could give me an example code, all I'm trying to do is make a code that saves which scene the player leaves off in, so that when the game starts it starts from that scene. I'm not trying to save any variables in the scene. I'm only trying to save which scene the player exited the game on, so that when he/she starts again they will resume from that level.
http://answers.unity3d.com/questions/18942/saving-and-loading-help-please - please search before posting duplicate questions.
I posted a fairly detailed reply to your thread on this topic in the forums, and quite a few others posted to your other threads on this topic as well. It would probably be more fruitful (I$$anonymous$$O) to continue the discussion in those threads rather than start new threads on the topic. If there are aspects of the answers you received that you're not clear on, just ask whatever follow-up questions you have and people will be happy to help.
Answer by Heratitan · Oct 06, 2010 at 03:25 AM
The way I would do this would be to just have an integer variable in your PlayerPrefs and every time you finish a level you save the level number off to the PlayerPrefs. Then, when the person plays again you just get the level number from the PlayerPrefs and load that level. For Example: At the end of a level:
var levelnumber : int;
function OnEndGame () { PlayerPrefs.SetInt("LastLevel", levelnumber); }
That would set the PlayerPrefs to your last level.
When the person plays again:
function LoadLevel () {
var leveltoload = PlayerPrefs.GetInt("LastLevel");
Application.LoadLevel(leveltoload);
}
Hope this helps.
does this works on iphone/ipad? cuz dunno about makin encrypted txt files for the ipad, or addin them in the game
Yes, Actually I think this is the what I used for my very first iPhone Game.
Your answer
Follow this Question
Related Questions
Can't save script 1 Answer
Saving/Loading Vertices Efficiently 2 Answers
Fastest Way To Save/Load a SkinnedMeshRenderer at Runtime 0 Answers