Mobile Game Progression

How to save Players Gem count between scenes

Now that we have created a proper gem counter for our player we need to allow the total gem count be updated throughout the different scenes. Currently our gem count resets once we enter a new scene, in order to fix this we will require two functions. A save function to save the current amount of gems collected and then a Load function which would override the current total gems collected from the previous scene.

Game Manager Script:

I am going to place everything related to saving and loading the total amount of gems within our Game Manager script. This allows the Game saved Data to be able to access every script component available since the game manager is an singleton.

I will be working with a function called “Player Prefs”. This function is able to store data within the capacities of Integers, Floats and Strings. Since our gem count is an integer using Player Prefs is perfect. Within our Game Manager script, I decided to create a new public method called “Saved Gems”. In this method I used the Player Preference function to set the int called “total Gems” to be the Players total Gem.

I managed to gain access to the Player script using get component earlier

The next public method is called “Load Gems”. In this method I created an new integer variable called “loadGemNumber” which will be the total saved gems from the saved data. Then I update the data by telling the player total gem is now equal the Loaded Gems Number. I also update the UI Manager HUD so it is visually shown.

Applying the Load and Saved data:

Now that we have our two public method available it is time to place them within our scene whenever we need to save and load the data. In my situation I want to trigger the save data during the progression to the next stage.

When the player hits the Next Level Button, the Gems data would save.

Next within the player script In the start method, I decided to sneak in the load data.

Now every time the Player loads into the scene, the load gem count would also be loaded in.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Simon Truong

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.