SHARE
TWEET

HighscoreSystem

a guest Nov 28th, 2018 18 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top