Hello everyone, I want to add an item to the list when the my two gameobject is destroyed and saving it into a JSON file. The problem is, when I look at the json file, it only saves the last gameobject(last item from the list). I’ve been debugging it for 3 hours and I have no idea where’s the problem…
SaveManager
public static void Save(SaveData saveData)
{
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
string json = JsonUtility.ToJson(saveData);
File.AppendAllText(directory + filename, json);
}
public static SaveData Load()
{
fullPath = directory + filename;
SaveData saveData = new SaveData();
if (File.Exists(fullPath))
{
string json = File.ReadAllText(fullPath);
saveData = JsonUtility.FromJson<SaveData>(json);
}
return saveData;
}
GameObject
private void OnDestroy()
{
SaveData saveData = new SaveData();
saveData.scrollViews.Add(scrollView);
SaveLoad.Save(saveData);
}