【发布时间】:2015-09-08 19:11:02
【问题描述】:
到目前为止我所做的是在游戏中设置一个分数以每秒增加一个分数,让分数显示在游戏场景中,然后如果分数大于高分,则将高分设置为等于分数.到目前为止,这是我的代码:
bool gameOver;
public Text scoreText;
public Text highScoreText;
int score;
int highScore;
// Use this for initialization
void Start () {
score = 0;
highScore = 0;
InvokeRepeating ("scoreUpdate", 1.0f, 1.0f);
gameOver = false;
}
// Update is called once per frame
void Update () {
scoreText.text = "★" + score;
highScoreText.text = "★" + highScore;
}
public void gameOverActivated() {
gameOver = true;
if (score > highScore) {
highScore = score;
}
PlayerPrefs.SetInt("score", score);
PlayerPrefs.Save();
PlayerPrefs.SetInt("highScore", highScore);
PlayerPrefs.Save();
}
void scoreUpdate() {
if (!gameOver) {
score += 1;
}} }
当这段代码发生时,“游戏结束”等于真:
void OnCollisionEnter2D (Collision2D col) {
if (col.gameObject.tag == "enemyPlanet") {
ui.gameOverActivated ();
Destroy (gameObject);
Application.LoadLevel ("gameOverScene2");
}
}
我想要的是此时(当对象发生碰撞并且游戏结束时)以保存分数,然后加载游戏结束场景。如何在游戏结束时保存分数,然后将其与保存的高分一起加载到游戏结束场景中??
【问题讨论】:
标签: c# android unity3d-2dtools