I'm trying to make a program in Unity that consists of a user interface where I can create teams with several stats (health, mana, and exp), and manage the stats for each team. The team management itself seems to be working, but I'm struggling to create a save system.
New teams are created by instantiating a prefab object of the class Team
, which contains all the info on how a team works. With the help of a friend, I made the next save function, that adds the variables I want to keep from all the objects of the class Team to a list I save in a file via json:
public void Save()
{
List<Team> teams = getTeams();
StreamWriter sw = new StreamWriter("save.json");
sw.WriteLine(JsonConvert.SerializeObject(teams, new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
}));
sw.Close();
}
I'd like now to make a load function that sets the program to the same status it was before closing it, with the same teams and the same values each team had, but when reopening the program it starts with only the prefab team, and I don't know how to use the variables saved for each team in the list to create new instances with the same values the old teams had.
I hope the explanation is good enough for you to understand, and thank you in advance.