Quantcast
Viewing latest article 24
Browse Latest Browse All 1333

PlayerPrefs Highscore Problem

I'm developing a game that uses playerprefs to save the score and highscore, the problem is, everything works in unity editor, but when i build the app and install it on android, the highscore is not working at all. Since i'm using textmeshpro to display my score and highscore text in game, i have to convert the int (high and current) to string. Can anyone help me please? Here's my code : public class ScoreHandler : MonoBehaviour { public GameObject currentScore; public GameObject highScore; private TextMeshProUGUI currentScoreText; private TextMeshProUGUI highScoreText; private int current; private int high; // Start is called before the first frame update void Start() { currentScoreText = currentScore.GetComponent(); high = PlayerPrefs.GetInt("highScore"); highScoreText = highScore.GetComponent(); } void Update() { //change the current score currentScoreText.text = PlayerPrefs.GetString("currentScore"); //check if current score is higher than highscore current = System.Convert.ToInt32(PlayerPrefs.GetString("currentScore")); high = System.Convert.ToInt32(PlayerPrefs.GetString("highScore")); if(current > high) { high = current; highScoreText.text = high.ToString(); PlayerPrefs.SetString("highScore", System.Convert.ToString(current)); PlayerPrefs.Save(); } highScoreText.text = PlayerPrefs.GetString("highScore", System.Convert.ToString(high)); } }

Viewing latest article 24
Browse Latest Browse All 1333

Trending Articles



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