Saving highscore for multiple scenes
hi im new to unity, ive made a highscore script and it saves with playerprefs perfectly, only problem is that my game has more than one scene and the highscore for one scene is the same for the others, can someone help me in fixing this? im quite new and this is my only problem thats preventing me from finishing my game! thank u in advance
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public class ScoreManager : MonoBehaviour
{
public Text scoreText;
public Text hiScoreText;
public float scoreCount;
public float hiScoreCount;
public float pointsPerSecond;
public bool scoreIncreasing;
// Use this for initialization
void Start()
{
if (PlayerPrefs.GetFloat("HighScore") != 0)
{
hiScoreCount = PlayerPrefs.GetFloat("HighScore");
}
}
// Update is called once per frame
void Update()
{
if (scoreIncreasing)
{
scoreCount += pointsPerSecond * Time.deltaTime;
}
if (scoreCount > hiScoreCount)
{
hiScoreCount = scoreCount;
PlayerPrefs.SetFloat("HighScore", hiScoreCount);
PlayerPrefs.Save();
}
scoreText.text = "Score: " + Mathf.Round(scoreCount);
hiScoreText.text = "High Score: " + Mathf.Round(hiScoreCount);
}
}
Answer by gaming_man_is_gaming · May 31, 2021 at 05:02 PM
im trying to figure this out myself but i think u somehow have to save the variables on a unused scene then call the variables from that scene. i hope we can help each other with our ideas
Your answer
Follow this Question
Related Questions
How do I apply and save my game settings? 0 Answers
Loading and Saving High Score 1 Answer
Highscore and PlayerPrefs unity C# 1 Answer
How to disable the PlayerPrefs autosaving on quit ? 0 Answers