- Home /
Restarting the scene with save data
If you call the function SceneManager.LoadScene to reload the scene, but you implemented save data in the start function, would it overwrite the save data and completely reload the scene or your save data would be loaded along with the scene?
Can you give some example about what you mean by "implemented save data"? What data are you setting? :)
Lets say I make a game where I collect coins. If I restart the scene, I want the player to still have the coins they collected. Or let's say they close out of the app, they should still have their coins.
Answer by jackmw94 · Jan 12, 2021 at 07:08 PM
An easy way to implement persistent data is by using PlayerPrefs.
With this you can do things like:
PlayerPrefs.SetInt("PlayerCoins", 100);
and
int playerCoins = 0;
if (PlayerPrefs.HasKey("PlayerCoins"))
{
playerCoins = PlayerPrefs.GetInt("PlayerCoins");
}
To get and set data such as numbers of coins :)
If you have multiple players who could play on a single machine or multiple "saves" then you might want to make a more involved system to handle the keys with which you save your data.