本文介绍了在Unity C#中存储HighScore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在尝试在Unity中存储高分.如何保存最高分?
I'm currently trying to store a highscore in Unity. How do I get it to save the highscore?
这是我到目前为止所拥有的
This is what I have so far
private float gameTime = 0; //the time (in seconds) that the player has been playing the level
public void PlayerWin()
{
gameOver = true;
//Update the highscore
float bestTime = 0;
bool isNewHighscore = false;
//Pop up the win message
UIController.GameOver(WIN_MESSAGE, gameTime, bestTime, isNewHighscore);
}
推荐答案
您可能希望使用 PlayerPrefs .由于它似乎好像是按照bestTime变量(浮点类型)来跟踪分数,因此,您特别想使用 PlayerPerfs.SetFloat
You would want to use PlayerPrefs. Since it appears as if you're tracking the score by the bestTime variable (a float type) you would specifically want to use PlayerPerfs.SetFloat
您的代码将如下所示:
PlayerPrefs.SetFloat("highScore", bestTime);
这篇关于在Unity C#中存储HighScore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!