Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- first script:
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class highscore : MonoBehaviour {
- public Text bestscore;
- // Use this for initialization
- void Start () {
- bestscore.text = PlayerPrefs.GetFloat ("BestScore", 0).ToString (0.0);
- }
- // Update is called once per frame
- void Update () {
- }
- }
- ------------------------------------------------------------------
- Second script:
- ------------------------------------------------------------------
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class HUD : MonoBehaviour {
- float maxHealth = 100f;
- public static float health;
- public Text timeText;
- private float startTime;
- // Use this for initialization
- void Start () {
- startTime = Time.time;
- }
- // Update is called once per frame
- void Update () {
- float t = Time.time - startTime;
- string minutes = ((int)t / 60).ToString ();
- string seconds = (t % 60).ToString ("f0");
- timeText.text = minutes + ":" + seconds;
- }
- float currentBestScore = PlayerPrefs.GetFloat("Bestscore", 0);
- float currentScore = Time.time - startTime;
- if (currentScore < currentBestScore)
- {
- PlayerPrefs.setFloat("BestScore", currentScore);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement