显示当前分与历史最高分数

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class GameOver : MonoBehaviour
{
    public static GameOver _instance;

    public Text bestScore;
    public Text nowScoreText;

    void Awake()
    {
        _instance = this;
        this.gameObject.SetActive(false);
    }

    void Start()
    {
        //bestScore = GetComponent<Text>();
        //nowScore = GetComponent<Text>();
      
    }

    public void Show(float nowScore)
    {
        //这是设定一个存储float类型的数据的位置
        float histotyHighScore = PlayerPrefs.GetFloat("historyHighScore", 0);
        if (nowScore>histotyHighScore)
        {
            //将上面的位置的数据进行替换
            PlayerPrefs.SetFloat("historyHighScore",nowScore);
        }
        bestScore.text = "" + histotyHighScore;
        nowScoreText.text = "" + nowScore;
        this.gameObject.SetActive(true);
    }
}

 

posted @ 2016-04-06 19:58  礼桀  阅读(459)  评论(0)    收藏  举报