SHOW:
|
|
- or go back to the newest paste.
| 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 void Salvar(Personagem personagem, int id){
|
| 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 Personagem Carregar(int id){
|
| 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 | } |