Почему мой код сброса для сброса рекорда не работает? - PullRequest
0 голосов
/ 02 августа 2020

Почему мой код сброса для сброса рекорда не работает? Вот мой скопированный скрипт в единстве с использованием Visual Studio 2019.

using UnityEngine;
using UnityEngine.UI;

public class Score : MonoBehaviour
{

    public Transform player;
    public Text currentScoreText;
    public Text highScoreText;

    public const string highScoreKey = "HighScore";

    [Header("Score values")]
    [SerializeField] public int highScore = 0;
    [SerializeField] public int currentScore = 0;

    public void Start()
    {
        highScore = PlayerPrefs.GetInt(highScoreKey, 0);
        highScoreText.text = highScore.ToString();
        PlayerPrefs.Save();
        PlayerPrefs.DeleteKey("HighScore");
    }

    public void Update()
    {
        currentScore = Mathf.RoundToInt(player.position.z);
        currentScoreText.text = currentScore.ToString();

        if (currentScore > highScore)
        {
            highScore = currentScore;
            highScoreText.text = highScore.ToString();
            PlayerPrefs.SetInt(highScoreKey, highScore);
        }
    }

    public void OnDisable()
    {
        PlayerPrefs.SetInt(highScoreKey, highScore);
        PlayerPrefs.Save();

        Debug.Log("The high score is currently: " + highScore);
    }

    public void Reset()
    {
        PlayerPrefs.DeleteKey("HighScore");
    }
}
...