void Start() { ExperienceSave loadSave = new ExperienceSave(0, 0); if (System.IO.File.Exists(Application.persistentDataPath + @"\xp.json")) { string jsonSaveString = System.IO.File.ReadAllText(Application.persistentDataPath + @"\xp.json"); JsonUtility.FromJsonOverwrite(jsonSaveString, loadSave); } else { System.IO.File.Create(Application.persistentDataPath + @"\xp.json"); } currentXP = loadSave.currentXP; level = loadSave.level; Save(); maxXpArray.Add(50); maxXpArray.Add(200); maxXpArray.Add(500); for (int i = 2; i < length - 1; i++) { int dif = maxXpArray[i] - maxXpArray[i - 1]; maxXpArray.Add((Mathf.RoundToInt(dif + (10 * i) + maxXpArray[i]) / 10) * 10); } }
void Save() { ExperienceSave save = new ExperienceSave(currentXP, level); string jsonSaveString = JsonUtility.ToJson(save, true); System.IO.File.WriteAllText(Application.persistentDataPath + @"\xp.json", jsonSaveString); Invoke("Save", 5); }