- Home /
Question by
mirceaculita · Aug 16, 2017 at 10:11 AM ·
playerprefssave data
Save the state of a gameobject between scenes
Hello,
I am trying to add currency to my game and that means that the player has to collect coins from the map that get stored and later on he can buy upgrades from the shop.
My problem is that when I restart the game or reload the scene the coins are still there. I want to make a script that remembers the state of the coin between scenes. I have been using player prefs to store some data, but I can't figure out a way to save the state of the objects.
Comment
Answer by carlos170586001500 · Aug 16, 2017 at 12:06 PM
Use Object.DontDestroyOnLoad() in the script where you save all collected coins, the total amount, the player upgrades... https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html
Your answer
![](https://koobas.hobune.stream/wayback/20220612132823im_/https://answers.unity.com/themes/thub/images/avi.jpg)