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

PlayerPref resets the value,PlayerPref displays the stored value and then resets it

$
0
0
Hi, so I was trying to learn PlayerPrefs and so I built a simple counter that increments the count when clicked and saves it. The next time when you start the counter it starts the count where you had left. However, in my case, if you have stopped the count at 6 and then you want to start again the next count will be 7 but the one after that again starts with 1 and so on. Any help is appreciated. Script: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class CountText : MonoBehaviour { public Text countText; public int count; public void TextChange() { count++; } public void SaveData() { PlayerPrefs.SetInt("count", count); } public void LoadData() { print(PlayerPrefs.GetInt("count")); countText.text = PlayerPrefs.GetInt("count").ToString(); } } [1]: /storage/temp/165137-screenshot-2020-08-10-at-114157-am.png

Viewing all articles
Browse latest Browse all 1333

Trending Articles



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