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

PlayerPreffs not saving between plays?

$
0
0
So I just want to save 3 ints between different sessions, but the values don't get saved and loaded properly. I troubleshot the code and it works properly bc when I used two buttons to manually load and save while running the game it works fine. But between the sessions, it won't save anything. Could it be caused by the inconsistent line endings error? (I don't think so bc in other projects it still worked fine with the error.) using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; public int dayLevel; public int Cash; public int Diamonds; void Start() { Load(); } public void OnApplicationQuit() { Save(); } public void Load() { Debug.Log("Load"); dayLevel = int.Parse(PlayerPrefs.GetString("dayLevel", "1")); Diamonds = int.Parse(PlayerPrefs.GetString("Diamonds", "10")); Cash = int.Parse(PlayerPrefs.GetString("Cash", "100")); } public void Save() { Debug.Log("Saved"); PlayerPrefs.SetString("dayLevel", dayLevel.ToString()); PlayerPrefs.SetString("Diamonds", Diamonds.ToString()); PlayerPrefs.SetString("Cash", Cash.ToString()); }

Viewing all articles
Browse latest Browse all 1333

Trending Articles



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