JSON serialization is a human-readable format for saving data in Unity. Here's an example of how to use JSON serialization to save and edit a custom data class:
// Edit the saved data data.username = "JaneDoe"; data.score = 200;
[CreateAssetMenu(fileName = "PlayerData", menuName = "PlayerData")] public class PlayerData : ScriptableObject { public string username; public int score; } unity save edit
// Save the data using JSON serialization string json = JsonUtility.ToJson(data); Debug.Log(json); // Output: {"username":"JohnDoe","score":100}
// Edit the loaded data loadedData.username = "JaneDoe"; loadedData.score = 200; JSON serialization is a human-readable format for saving
PlayerPrefs is a straightforward way to save small amounts of data in Unity. Here's an example of how to use PlayerPrefs to save and edit a string value:
public class PlayerData { public string username; public int score; } data.score = 200
[Serializable] public class PlayerData { public string username; public int score; }