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

Player prefs won't save or be retrieved.

$
0
0
I'm trying to save the high score but it won't set the value for the scene when being called and won't even save resulting in the Debug.Log("NEW HIGHSCORE") to be spammed. What do? using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class pedometer : MonoBehaviour { public bool start; public bool gameOver; public float distance = 0f; public int speed = 1; void Update () { GameObject.Find("Canvas/Panel/HSCOREnumber").GetComponent().text = PlayerPrefs.GetInt("Highscore").ToString(); if (Input.GetMouseButton(0)) { distance += Time.deltaTime; start = true; GameObject.Find("Canvas/Panel/SCOREnumber").GetComponent().text = ((int)(distance)).ToString(); if (distance > PlayerPrefs.GetInt("Highscore")) { PlayerPrefs.SetInt("HighScore", (int)(distance)); Debug.Log("NEW HIGHSCORE" + (int)(distance)); PlayerPrefs.Save(); } } } }

Viewing all articles
Browse latest Browse all 1333

Trending Articles



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