Skip to main content
Update high score *after* updating score.
Source Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

First, you will want to add public float highscore; with your other variables at the top. Then, you will want to change the old code to this in your script. This is a very basic save system, and can easily be modified to fit the needs of the game. The comments in the code explain the script in further detail.

// Initiates before the first frame plays void StartUpdate()  {   // Loads theIncreases score atif start player is still LoadScore(); } alive // Initiates once per frame voidif Update() { // ChangesisPlayerAlive highscore== totrue)  current score if current{  score is higher  if (score > highscore) += Time.deltaTime * {scoreMulti; highscorescoreText.text = score;score.ToString("Score: 0");  }  // IncreasesChanges highscore to current score if playercurrent isscore stillis alivehigher   if (isPlayerAlivescore ==> truehighscore)   { score += Time.deltaTime * scoreMulti;  highscore = score;  scoreText.text = score.ToString("Score: 0");} } } // Saves the score when activated, from button, script, etc. void SaveScore() { PlayerPrefs.SetFloat("score", score); PlayerPrefs.SetFloat("highscore", highscore); PlayerPrefs.Save(); } // loads the score and highscore from the save file when activated, fromif button,there script,are etc.any void LoadScore() { score = PlayerPrefs.GetFloat("score", 0); highscore = PlayerPrefs.GetFloat("highscore", 0); } 

First, you will want to add public float highscore; with your other variables at the top. Then, you will want to change the old code to this in your script. This is a very basic save system, and can easily be modified to fit the needs of the game. The comments in the code explain the script in further detail.

// Initiates before the first frame plays void Start()  { // Loads the score at start  LoadScore(); }  // Initiates once per frame void Update() { // Changes highscore to current score if current score is higher  if (score > highscore)  { highscore = score; }  // Increases score if player is still alive if (isPlayerAlive == true) { score += Time.deltaTime * scoreMulti;  scoreText.text = score.ToString("Score: 0"); } } // Saves the score when activated, from button, script, etc. void SaveScore() { PlayerPrefs.SetFloat("score", score); PlayerPrefs.SetFloat("highscore", highscore); PlayerPrefs.Save(); } // loads the score and highscore from the save file when activated from button, script, etc. void LoadScore() { score = PlayerPrefs.GetFloat("score", 0); highscore = PlayerPrefs.GetFloat("highscore", 0); } 

First, you will want to add public float highscore; with your other variables at the top. Then, you will want to change the old code to this in your script. This is a very basic save system, and can easily be modified to fit the needs of the game. The comments in the code explain the script in further detail.

void Update() {   // Increases score if player is still alive if (isPlayerAlive == true)  {  score += Time.deltaTime * scoreMulti; scoreText.text = score.ToString("Score: 0");  // Changes highscore to current score if current score is higher   if (score > highscore)   { highscore = score;  } } } // Saves the score when activated, from button, script, etc. void SaveScore() { PlayerPrefs.SetFloat("score", score); PlayerPrefs.SetFloat("highscore", highscore); PlayerPrefs.Save(); } // loads the score and highscore from the save file, if there are any void LoadScore() { score = PlayerPrefs.GetFloat("score", 0); highscore = PlayerPrefs.GetFloat("highscore", 0); } 
Post Undeleted by OKprogrammer
Fixed the script.
Source Link
OKprogrammer
  • 522
  • 1
  • 7
  • 20

First, you will want to add public float highscore; with your other variables at the top. Then, you will want to add thischange the old code intoto this in your start functionscript. This is a very basic save system, and can easily be modified to fit the needs of the game. The comments in the code explain the script in further detail.

 // SavesInitiates before the scorefirst andframe highscoreplays void intoStart() the {  save file  // Loads the score =at PlayerPrefs.GetFloatstart LoadScore("score");  } // Initiates once highscoreper =frame void PlayerPrefs.GetFloatUpdate("highscore"); { // Changes highscore to current score if current score is higher if (score > highscore) { highscore = score; }  // Increases score if player is still alive if (isPlayerAlive == true) { score += Time.deltaTime * scoreMulti; scoreText.text = score.ToString("Score: 0"); } } // Saves the score when activated, from button, script, etc. void SaveScore() { PlayerPrefs.SetFloat("score", score); PlayerPrefs.SetFloat("highscore", highscore); PlayerPrefs.Save(); } // loads the score and highscore from the save file when activated from button, script, etc. void LoadScore() { score = PlayerPrefs.GetFloat("score", 0); highscore = PlayerPrefs.GetFloat("highscore", 0); }  

First, you will want to add public float highscore; with your other variables at the top. Then, you will want to add this code into your start function. This is a very basic save system, and can easily be modified to fit the needs of the game. The comments in the code explain the script in further detail.

 // Saves the score and highscore into the save file  score = PlayerPrefs.GetFloat("score");   highscore = PlayerPrefs.GetFloat("highscore"); // Changes highscore to current score if current score is higher if (score > highscore) { highscore = score; } 

First, you will want to add public float highscore; with your other variables at the top. Then, you will want to change the old code to this in your script. This is a very basic save system, and can easily be modified to fit the needs of the game. The comments in the code explain the script in further detail.

// Initiates before the first frame plays void Start()  {  // Loads the score at start LoadScore(); } // Initiates once per frame void Update() { // Changes highscore to current score if current score is higher if (score > highscore) { highscore = score; }  // Increases score if player is still alive if (isPlayerAlive == true) { score += Time.deltaTime * scoreMulti; scoreText.text = score.ToString("Score: 0"); } } // Saves the score when activated, from button, script, etc. void SaveScore() { PlayerPrefs.SetFloat("score", score); PlayerPrefs.SetFloat("highscore", highscore); PlayerPrefs.Save(); } // loads the score and highscore from the save file when activated from button, script, etc. void LoadScore() { score = PlayerPrefs.GetFloat("score", 0); highscore = PlayerPrefs.GetFloat("highscore", 0); }  
Post Deleted by OKprogrammer
added 63 characters in body
Source Link
OKprogrammer
  • 522
  • 1
  • 7
  • 20

First, you will want to add public float highscore; with your other variables at the top. Then, you will want to add this code into your start function. This is a very basic save system, and can easily be modified to fit the needs of the game. The comments in the code explain the script in further detail.

 // Saves the score and highscore into the save file score = PlayerPrefs.GetFloat("score"); highscore = PlayerPrefs.GetFloat("highscore"); // Changes highscore to current score if current score is higher if (score > highscore) { highscore = score; } 

First, you will want to add public float highscore; with your other variables at the top. Then, you will want to add this code into your start function. This is a very basic save system, and can easily be modified to fit the needs of the game.

 // Saves the score and highscore into the save file score = PlayerPrefs.GetFloat("score"); highscore = PlayerPrefs.GetFloat("highscore"); // Changes highscore to current score if current score is higher if (score > highscore) { highscore = score; } 

First, you will want to add public float highscore; with your other variables at the top. Then, you will want to add this code into your start function. This is a very basic save system, and can easily be modified to fit the needs of the game. The comments in the code explain the script in further detail.

 // Saves the score and highscore into the save file score = PlayerPrefs.GetFloat("score"); highscore = PlayerPrefs.GetFloat("highscore"); // Changes highscore to current score if current score is higher if (score > highscore) { highscore = score; } 
Source Link
OKprogrammer
  • 522
  • 1
  • 7
  • 20
Loading