如何制作计时器就像我得到的计分器一样

时间:2014-02-19 07:36:27

标签: unity3d unityscript

var score = 0;
var mySkin: GUISkin;
var GUIScore: GUIText;

function Start() {
    GUIScore.text = "Score: 0";
}

function OnTriggerEnter(other: Collider) {
    if (other.tag == "MissionComplete") {
        SaveScore();
    }
    if (other.tag == "Coin") {
        Debug.Log("Other object is a coin");
        score += 50;
        GUIScore.text = "Score: " + score;
        Debug.Log("Score is now " + score);
        Destroy(other.gameObject);
    } else if (other.tag == "SpecialCoin") {
        Debug.Log("Other object is a coin");
        score += 150;
        GUIScore.text = "Score: " + score;
        Debug.Log("Score is now " + score);
        Destroy(other.gameObject);
    } else if (other.tag == "Rock") {
        Debug.Log("Other object is a rock");
        score += -20;
        GUIScore.text = "Score: " + score;
        Debug.Log("Score is now " + score);
        if (score <= 0) {
            Application.LoadLevel("NextLevel");
        }
    }
}

function SaveScore() {
    if (score > PlayerPrefs.GetInt("JScore")) {
        PlayerPrefs.SetInt("JScore", score);
    }
    Application.LoadLevel("LoadScene");
}

我想要一个在完成目标后记录的计时器 就像一个记录高分榜时间的时间记录器。

1 个答案:

答案 0 :(得分:0)

查看Save Game JSON + Binary资产商店插件 https://www.assetstore.unity3d.com/#/content/3675 您也可以将数据存储在xml文件中,也可以使用PlayerPrefs,但理想情况下,您需要更加结构化的内容。