Unity:如何加快分数倒计时

Unity: How to speed up score countdown

一个简单的问题。我正在玩一些教程中的小游戏,但想添加一个每秒减少的分数。我设法通过下面提供的代码做到了这一点,但分数一次只降低了 1 秒。我想以某种方式加快它的速度,这样它每秒可以下降 150。我尝试了一些东西,但它们没有用,而且大多数甚至没有在游戏内的 GUI 上记录更改。感谢您的帮助!

代码:

public class GameOver : MonoBehaviour {

    public GameObject gameOverScreen;
    public Text Score;
    public Text Highscore;

    bool gameOver;
    private int score = 12000;

    void Start () {
        FindObjectOfType<PlayerController>().OnPlayerDeath += OnGameOver;
    }


    public void Update () {

        Score.text = Mathf.Round(score - Time.timeSinceLevelLoad).ToString();

        if (gameOver)
        {
            if (Input.GetKeyDown (KeyCode.Space))
            {
                SceneManager.LoadScene(1);
            }
        }
    }

     void OnGameOver()
    {
        gameOverScreen.SetActive (true);
        Highscore.text = Mathf.Round(score - Time.timeSinceLevelLoad ).ToString();

        gameOver = true;
    }
}

不要重复自己。做一个函数来获取分数。

int GetScore() {
    return score - (int)Time.timeSinceLevelLoad * 150;
}

然后使用它。

void Update() {
    Score.text = GetScore().ToString();
}

更改此部分

 Score.text = Mathf.Round(score- Time.deltaTime*150).ToString(); 

--

public void Update () {

            Score.text = Mathf.Round(score- Time.deltaTime*150).ToString();

            if (gameOver)
            {
                if (Input.GetKeyDown (KeyCode.Space))
                {
                    SceneManager.LoadScene(1);
                }
            }
        }