Quantcast
Channel: Questions in topic: "unitywebplayer"
Viewing all articles
Browse latest Browse all 452

Playerprefs issue in WebGL

$
0
0
Hi, I'm using playerprefs in my WordSearch Game that I built with Webgl. The Issue is appear when I close my game during the game play for several times. It's automatically starts with random countdown value such as 20, 140 etc with previous score(Sometimes Not the exact score that should be saved). Here's the code that I'm using playerpreds... [SerializeField] public float currentLevelScore = 0.0f; [SerializeField] private float timeLeft; [SerializeField] private string accessToken = ""; void Awake() { GetPlayerPrefData(); } void Start() { if(timeLeft == fixedTime) { PauseGame(); } //Retrive Saved Player prefs Data if (PlayerPrefs.GetFloat("timeLeft")<150 && PlayerPrefs.GetFloat("timeLeft") > 0) { StartGameCanvas.SetActive(false); } else { if(PlayerPrefs.GetFloat("timeLeft") == 150) { StartGameCanvas.SetActive(true); } } if (PlayerPrefs.GetFloat("timeLeft").Equals(0) || PlayerPrefs.GetFloat("timeLeft").Equals(null)) { PlayerPrefs.SetFloat("timeLeft", fixedTime); } } void GetPlayerPrefData() { accessToken = PlayerPrefs.GetString("accessToken"); currentLevelScore = PlayerPrefs.GetFloat("currentLevelScore"); float countdownTime = PlayerPrefs.GetFloat("timeLeft"); if (countdownTime <= 0) { timeLeft = fixedTime; } else { timeLeft = countdownTime; } } //This function is calls when the Time is up or user hit the quit button public void ResetAllData() { float defaultScore = 0; string defaultAccessToken = null; PlayerPrefs.SetFloat("currentLevelScore", defaultScore); PlayerPrefs.SetFloat("timeLeft", fixedTime); PlayerPrefs.SetString("timeLeft", defaultAccessToken); PlayerPrefs.Save(); } This issue is only occur after build the game. It's works fine in the editor. Can anyone give me an idea or help to solve this problem? any suggestions would be highly appreciated...

Viewing all articles
Browse latest Browse all 452

Trending Articles



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