0
我到目前为止所做的是在游戏中设置每秒增加的分数,获得在游戏场景中显示的分数,然后设置高分等于分数if得分高于高分。这是到目前为止我的代码:在Unity2d中保存和加载高分
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;
}} }
“GAME OVER”等于真当此代码发生:
void OnCollisionEnter2D (Collision2D col) {
if (col.gameObject.tag == "enemyPlanet") {
ui.gameOverActivated();
Destroy (gameObject);
Application.LoadLevel ("gameOverScene2");
}
}
我想在这一点上(当物体发生碰撞和游戏结束是真),以保存分数,然后加载场景上的游戏。如何在比赛结束时保存比分,然后将比赛中的比分加载到场上以及保存的比分?