遇到高分问题,而不是保存高分

时间:2019-07-04 12:52:32

标签: c# unity3d

我在实施high score时遇到麻烦。它以常规分数计,但不保存任何高分数或分数,它只需要保存并在Text对象中显示当前高分数(如果当前分数大于保存的高分数,则设置当前分数作为高分)。我尝试了各种各样的东西,但是那根本行不通。

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

public class ScoreScr : MonoBehaviour {

    public static int scoreValue = 0;
    public Text score;
    public Text HighscoreText;
    public static int highscore;

    void Start () {
        highscore = PlayerPrefs.GetInt("HighScore", 0);
        HighscoreText.text = "" + highscore;
        score = GetComponent<Text>();
        scoreValue = 0;
    }

    void Update () {
        score.text = "" + scoreValue;
    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class hazzCollision : MonoBehaviour {

    private void OnCollisionEnter(Collision col){
        if(col.gameObject.tag == "Platform"){
            this.gameObject.SetActive(false);
            ScoreScr.scoreValue += 1;
        }
        if(col.gameObject.tag == "Player"){
            if(PlayerPrefs.GetInt("HighScore", 0) < ScoreScr.scoreValue){
                    PlayerPrefs.SetInt("HighScore", ScoreScr.scoreValue);

                    PlayerPrefs.Save();
            }
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
        }
    }
}

我获得高分的结果是,它只计入常规分数,仅此而已。

0 个答案:

没有答案