Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1. first script:
  2.  
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7.  
  8. public class highscore : MonoBehaviour {
  9.  
  10.     public Text bestscore;
  11.  
  12.     // Use this for initialization
  13.     void Start () {
  14.         bestscore.text = PlayerPrefs.GetFloat ("BestScore", 0).ToString (0.0);
  15.     }
  16.    
  17.     // Update is called once per frame
  18.     void Update () {
  19.        
  20.     }
  21. }
  22.  
  23.  
  24. ------------------------------------------------------------------
  25. Second script:
  26. ------------------------------------------------------------------
  27. using System.Collections;
  28. using System.Collections.Generic;
  29. using UnityEngine;
  30. using UnityEngine.UI;
  31.  
  32. public class HUD : MonoBehaviour {
  33.  
  34.     float maxHealth = 100f;
  35.     public static float health;
  36.  
  37.     public Text timeText;
  38.     private float startTime;
  39.  
  40.     // Use this for initialization
  41.     void Start () {
  42.        
  43.         startTime = Time.time;
  44.     }
  45.    
  46.     // Update is called once per frame
  47.     void Update () {
  48.  
  49.         float t = Time.time - startTime;
  50.  
  51.         string minutes = ((int)t / 60).ToString ();
  52.         string seconds = (t % 60).ToString ("f0");
  53.         timeText.text = minutes + ":" + seconds;   
  54.     }
  55.  
  56.     float currentBestScore = PlayerPrefs.GetFloat("Bestscore", 0);
  57.     float currentScore = Time.time - startTime;
  58.  
  59.     if (currentScore < currentBestScore)
  60.     {
  61.         PlayerPrefs.setFloat("BestScore", currentScore);
  62.     }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement