Home > Enterprise >  how to make class variables not reset when closing unity
how to make class variables not reset when closing unity

Time:06-23

I'm trying to make a game where the user can input term and definition pairs and save them after the game closes.

These variables are in a script attached to a manager object.


    public Dictionary<string, string> TermDefinitionPairs;
    public Dictionary<string, int> TermPriorityValuePairs;
    public List<string> unseenTerms;

    private void AddTerm(string term, string definition)
    {
        TermDefinitionPairs[term] = definition;
        unseenTerms.Add(term);
        // Debug.Log(unseenTerms.Count);
    }

How can I make them save even after the game closes? I tried to use playerprefs but they can't hold those data structures.

CodePudding user response:

You can save it as a JSON file (serialize) and then load it on the next time (deserialize) to get all the data you need.

Here is an example of this.

Hope it helps!

CodePudding user response:

i use this video.Save load system in unity

in this way you need to save variables to binary file. but i tested and it works good.

  • Related