我试图根据玩家的“Z”位置添加一个高分。
我不明白出了什么问题。
void Start()
{
highScore.text = PlayerPrefs.GetInt("HighScore", 0).ToString();
}
void UpdateScore()
{
string number = player.position.z.ToString();
highScore.text = score.text.ToString();
PlayerPrefs.SetInt("HighScore", number); //here is where i get the error
}
为什么将位置 (float) 转换为字符串,然后尝试将字符串转换为 int ?
只需将播放器的 z 位置圆形/地板/天花板:
int number = Mathf.RoundToInt( player.position.z ) ;
highScore.text = score.text.ToString();
PlayerPrefs.SetInt("HighScore", number);
转换为字符串并解析对资源不是很友好,特别是如果你每帧都这样做。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句