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

Script with PlayerPrefs is not working on a different computer

$
0
0
Good day all, I have a project I'm working on and I'm saving the highscore using PlayerPrefs. Everything works fine on my laptop but recently, I bought a new computer so I've decided to transfer the project there. However, the script that saves and displays the highscore doesn't work at all. I'm not sure why this is happening. This is my script: public class Timer : MonoBehaviour { public Text timerText; public Text highscore; public GameObject gameOverMenu; public GameObject gameCompleteMenu; private float startTime; // Start is called before the first frame update void Start() { startTime = Time.time; highscore.text = "Highscore: " + PlayerPrefs.GetFloat("HighScore", 0).ToString(); } // Update is called once per frame void Update() { InputDevice device = InputDevices.GetDeviceAtXRNode(inputSource); float t = Time.time - startTime; string minutes = ((int)t / 60).ToString("00.##"); string seconds = (t % 60).ToString("00"); timerText.text = minutes + ":" + seconds; if (device.IsPressed(InputHelpers.Button.MenuButton, out bool isPressed) && isPressed) { // setting time scale to 0 so that everything in the scene stops when ESC is pressed if (Time.timeScale == 1) { Time.timeScale = 0; } // Debug.Log("You have quit the game"); GameFinished(); // calling the GameFinished method in order to display the high score } } void GameFinished() { float t = Time.time - startTime; if (t > PlayerPrefs.GetFloat("HighScore", float.MaxValue)) { PlayerPrefs.SetFloat("HighScore", t); highscore.text = "Highscore: " + t.ToString("00") + " seconds"; PlayerPrefs.Save(); } } ---------- What could be the issue? I'm not getting any errors or anything at runtime either so I'm kinda stuck.

Viewing all articles
Browse latest Browse all 1333

Trending Articles



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