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

How to Save&Load Best Time in PlayerPrefs

$
0
0
I've tried many examples from the internet, but none of them works. it's been 3days i stuck with this problem. I want to create a simple Save System that stores the fastest Time of a player when completing a level. ---------- public TextMeshProUGUI bestText; // Text for Best Time public TextMeshProUGUI currTimeText; public bool isFinished = false; // Check if game has finished float timer; private void Start() { if (PlayerPrefs.HasKey("BestTime")) { bestText.text = PlayerPrefs.GetFloat("BestTime").ToString("f2"); } } private void Update() { currTimeText.text = timer.ToString("f2"); if (!isFinished) { timer += Time.deltaTime; } else { Debug.Log(timer); timer += 0; if (timer < PlayerPrefs.GetFloat("BestTime", float.MaxValue)) { PlayerPrefs.SetFloat("BestTime", timer); bestText.text = timer.ToString("f2"); PlayerPrefs.Save(); } } }

Viewing all articles
Browse latest Browse all 1333

Latest Images

Trending Articles



Latest Images

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