torstai 15. syyskuuta 2016

Unity platformer - saving and loading

NAV15AP

1. jakso lukuvuonna 2016-2017

Now you’re going to learn how to save and load using playerprefs.

First you need something to save. If you did the previous checkpoint assignment, then you can save that. Start by creating empty game object named Game manager. Give FSM to that game object named load and save and make two states in that FSM.



In the start state you want to load your saved things. This is done with playerprefs get int action if your loadable variable is int type. There are also playerpref options for string and float types. Because this time you have only one variable set count to one. Name your key so that it’s logical. Then select your int variable for the variable section. You might also want to create load event and set is as global transition in case you’ll need to load at some other point at the game.



Create new state and a global transition event called save. Use playerprefs set int actions and select same values as you had in the loading state.



Then you need to modify the checkpoint FSM. In the last state add action send event by name. Specify game object and choose the game manager as the object in which you want to send event. Select save and load as the FSM and send your save event. This will save the checkpoint and if game is closed then player is able to pick up where the checkpoint was activated.


Ei kommentteja:

Lähetä kommentti