So I have this infinite runner type of game, subway surfers style. I chose a method where the player doesn't move, and instead the obstacles move towards him. My score is a float and it increases as time passes. However, I'm unable to figure out how can you save this as a highscore. I tried a few methods but most of them were for int so it didn't work out. Here is what I have for the score counting. It's currently missing the save score part completely.
public class GameManagerC : MonoBehaviour { float score = 0; public float scoreMulti = 5; void Update() { if (isPlayerAlive == true) { score += Time.deltaTime * scoreMulti; scoreText.text = score.ToString("Score: 0"); } } EDIT: Many of you asked how I tried to implement the code I've found so here it is:
public float score; public float highScore; void Start() { score = PlayerPrefs.GetFloat("score"); highScore = PlayerPrefs.GetFloat("highScore"); if (score > highScore) highScore = score; StartGame(); } // Update is called once per frame void Update() { if (isPlayerAlive == true) { score += Time.deltaTime * scoreMulti; scoreText.text = score.ToString("Score: 0"); } }