Skip to content

Instantly share code, notes, and snippets.

@arkms
Created March 3, 2017 05:15
Show Gist options
  • Save arkms/daece54b588585884df97693eb44ac73 to your computer and use it in GitHub Desktop.
Save arkms/daece54b588585884df97693eb44ac73 to your computer and use it in GitHub Desktop.
A easy and fast way to save a lot of vars in Unity
using UnityEngine;
public class SaveData : MonoBehaviour
{
public SAVEDATACLASS progreso; //es visible desde Inspector
public void Guardar()
{
//Generamos el formato Json
string Archivo = JsonUtility.ToJson(progreso);
//Lo guardamos con PlayerPrefs
PlayerPrefs.SetString("KeySave", Archivo);
}
public void Cargar()
{
string Archivo = PlayerPrefs.GetString("KeySave");
//Solo seguridad que si exista algo
if (!string.IsNullOrEmpty(Archivo))
{
progreso= JsonUtility.FromJson<SAVEDATACLASS>(Archivo);
}
}
}
[System.Serializable]
public class SAVEDATACLASS
{
public int UnInt;
public string UnString;
public float UnFloat;
public bool UnBool;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment