Quantcast
Channel: Questions in topic: "playerprefs"
Viewing all articles
Browse latest Browse all 1333

How to serialize multiple json objects from playerprefs

$
0
0
So, I am trying to create a character creation system using PlayerPrefs (it is not my first choice, but since I am using a website with no back-end I am very limited in what I Can do for saves). Basically what I have it doing: Is it itll detect a key, if it is there just add on to the character list, otherwise it'll just create a single save. Script: using UnityEngine; public static class SavePlayer { public static void SaveCharacter (Player player) { PlayerData data = new PlayerData(player); string jsonData; if (PlayerPrefs.HasKey("characters")) { //Get all Character Data jsonData = PlayerPrefs.GetString("characters"); jsonData = jsonData + ", " + JsonUtility.ToJson(data); PlayerPrefs.SetString("characters", jsonData); PlayerPrefs.Save(); } else { jsonData = JsonUtility.ToJson(data); PlayerPrefs.SetString("characters", jsonData); PlayerPrefs.Save(); } } } Heres is the playerprefs: { "name":"TestTwo", "cOne":"Adventurer", "cTwo":"None", "fStats":[5,5,5,5,5,5,5], "sPoints":5 }, { "name":"TestThree", "cOne":"Adventurer", "cTwo":"None", "fStats":[5,5,5,5,5,5,5], "sPoints":5 }

Viewing all articles
Browse latest Browse all 1333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>