Saving data in different scenes
I'm doing a simulation game and I have a question, how do I save the important data for me, that is, money, hp, mood, food. I make the game for the first time and did what would happen in different scenes, if it's wrong, please tell me about it.
I think I'm doing it wrong because it needs to be saved every second, can I do something like a button on which only the main part changes and the statistics does not get touched?
Answer by agray427 · Jan 15, 2018 at 07:40 PM
It would be great if you could provide code so we have an understanding of what you are trying to accomplish, but saving information like that is relatively easy. Depending on how much you have changes the recommendation I give you. If it's a little, I would suggest Player Prefs which is built right in to unity. If it's something complex with a lot of values and you're attempting to save several classes, Player Prefs probably won't be the best route to go. Anything would work though honestly. Either way, I recommend creating a class that holds all of that data and using JSON, BinaryFormatter, or XML to save the data to the disk. I have a tutorial for serializing data, but it is for more advanced users. You can certainly try looking it over. I explain things thoroughly enough for you to understand at least the topic I'm sharing with you. https://graymattertutorials.wordpress.com/2018/01/15/serialization-with-json-net-in-unity-3d/