Simple save/load scripting for multi level iOS game.

I understand (and have read) the many posts for saving and loading PlayerPrefs for iOS games but I think my problem is a little different especially because I have multiple levels in my game and I write in JavaScript.

I have 5 levels in my game and I’m trying to have a save game button during the course of the game and a load game button on the main menu. This is what I have so far: I created a small GUI Texture image of a small floppy disk in the upper right corner of all the level’s screens and I use the OnMouseDown command to activate it but I don’t know how to save the level and the position of the first person character when that icon button is pressed so that when the game is completely exited you can load it back to that spot when you select the load button on the main menu screen (of which I have the button working but I don’t know how to script the load to get back to the last saved position).

I don’t need to worry about anything else but the level and X,Y, and Z position of the player for that level.

Any help to write or suggestions as to where I can find the info to write the JavaScript I’m trying to write would be GREATLY appreciated.

Thanks so much in advance!!!

Tom

You didn’t specifically ask any questions, so I’m going to address some of the things you mentioned. playerTransform is the transform of the player, which you’ll have to figure out how to get (check out the GameObject.Find* methods).

  • Save the level: PlayerPrefs.SetInt(“SavedLevel”, Application.loadedLevel);
  • Save the player position: PlayerPrefs.SetFloat(“PlayerX”, playerTransform.position.x);
  • Same for y and z

Then, to load your saved data:

if (PlayerPrefs.HasKey("SavedLevel"))
  Application.LoadLevel(PlayerPrefs.GetInt("SavedLevel"));

etc.