Hi, I am working on a game and I am able to make a high score system using PlayerPrefs. But when I build my project to my android device the high score is the same as on my pc and when I get a higher score, the high score text doesn’t update. Note this only happens on my android device. Everything works well on pc. How would I fix this? Any help is appreciated.
using UnityEngine;
using TMPro;
using UnityEngine.SceneManagement;
using System;
using System.Diagnostics;
public class Score : MonoBehaviour
{
public TextMeshProUGUI scoreText;
public TextMeshProUGUI scoreAtEndText;
public TextMeshProUGUI highscoreText;
public TextMeshProUGUI newBestText;
public Player player;
public float score;
public bool scoreIncrease = true;
void Start()
{
highscoreText.enabled = false;
highscoreText.text = "BEST: " + PlayerPrefs.GetFloat("Highscore", 0).ToString("0");
PlayerPrefs.Save();
highscoreText.ForceMeshUpdate(true);
highscoreText.enabled = true;
}
void Update()
{
if (scoreIncrease) { score += Time.deltaTime * 60; }
else { score += 0; }
scoreText.text = score.ToString("0");
scoreAtEndText.text = "SCORE: " + score.ToString("0");
if (score > PlayerPrefs.GetFloat("Highscore", 0))
{
PlayerPrefs.SetFloat("Highscore", score);
PlayerPrefs.Save();
highscoreText.text = "BEST: " + score.ToString("0");
newBestText.gameObject.SetActive(true);
}
}
}