Guest User

HighscoreSystem

a guest
Nov 28th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6.  
  7. public class HighscoreSystem : MonoBehaviour
  8. {
  9. public Text scoreText;
  10. public Text highscoreText;
  11.  
  12. int score;
  13. int highscore;
  14.  
  15. void Start ()
  16. {
  17. score = PlayerPrefs.GetInt("Score");
  18. highscore = PlayerPrefs.GetInt("Highscore");
  19.  
  20. if(score > highscore)
  21. {
  22. PlayerPrefs.SetInt("Highscore", score);
  23. highscore = score;
  24. }
  25.  
  26. scoreText.text = "Score: " + score;
  27. highscoreText.text = "Highscore: " + highscore;
  28.  
  29. PlayerPrefs.SetInt("Score", 0);
  30. }
  31.  
  32. public void RestartGame()
  33. {
  34. SceneManager.LoadScene(0);
  35. }
  36. }
Add Comment
Please, Sign In to add comment