Extremely confused with saving! ! Please help!

I have so many questions that I can’t seem to find in the internet! Please help me answer all these questions! Thanks:

1.) How do I save data? Example: If the player buys a gun from a store, he will be able to access it from another menu even if he switched scenes. How do I do this?

2.) How can I save any piece of data so that if the player closes the game then opens it up an hour later, all his high scores and money and inventory will be there?

3.) What’s the best way to save a game? What is player prefs? How many different ways can I save a game and what is the best?

4.) I’m looking through the tutorials and people are saying to use static things. What’s static? What does it do?

5.) How can I write xml files? I can’t find any tutorials! Please tell me where you learned to write xml files.

Thanks guys. I had never been so confused in my life! I have read so many ttutorials that never seem to explain anything! Everyone explains everything differently and they keep themselves. I am so sorry for the truck load amount of questions. Please explain to me how to save as if I didn’t know a single thing about saving. Thanks so much

Loads of questions!!

1/4/ You save data from scene to scene using various way, you can have a static class that keeps track of your information. Since a static class keeps its data even when you change scene (due to its nature) you can easily pass and retrieve info. But that works only for one object like the player or you need a huge class.
Static means the members belong to the class as opposed to instance members:

public class StormTrooper{
int force = 0;
static string Group = “Empire”;
}

In the class above, an object of type StormTrooper has an integer that is different for all stortrooper. But the Group is static so they all share the same variable which belongs to the class StormTrooper.

If you need to save data for many objects, you can have a storage class, instantiate an object of that class and use DontDestroyOnLoad, collect your info on the other side and destroy the object.

2/ Static won’t do it to save permanent data, to do so you need to save on a file. This file can be a simple txt file using the .NET StreamWriter but that is not so safe since it can be easily modified. You can also use some MD5 or other encryption so that it gets harder to play with the value. That is until the guy realizes what encryption you are using.

You can also use a dat file which is just a type of file for data.

Or you can use PlayerPrefs, which saves any info as a string Unity - Scripting API: PlayerPrefs
PlayerPrefs saves the data as a string on the hard drive. As a result, it is permanent. You can retrieve info between scenes or between sessions.

Other way is to save on a server, using a connection and a php script. Issue is that you can only play the game if you have a connection (well, who does not…)

For all of those cases, you should first have a look at the UnitySerializer for free on the Asset Store.