Advertisement
LeonMMS

Untitled

Oct 9th, 2020
1,053
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //primeira classe
  2. public class Personagem {
  3.     public string nome;
  4.     public int classe;
  5.     public int vida;
  6.     public int vigor;
  7.     public int agilidade;
  8.     public int folego;
  9.     public int sorte;
  10.     public string GetJson(){
  11.         return JsonUtility.ToJson(this);
  12.     }
  13. }
  14. // segunda classe
  15. using System.IO;
  16. public class SalvarCarregar{
  17.     public static void Salvar(Personagem personagem, int id){
  18.             string path = Application.persistentDataPath + id.ToString() + ".json";
  19.             File.WriteAllText(path, personagem.GetJson());
  20.     }
  21.     public static Personagem Carregar(int id){
  22.         string path = Application.persistentDataPath + id.ToString() + ".json";
  23.         return JsonUtility.FromJson<Personagem>(File.ReadAllText(path));
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement