有人知道为什么高分不起作用吗?在游戏中,得分系统有效,但高分不起作用。我尝试过很多方法,但都不起作用。
using UnityEngine;
using UnityEngine.UI;
using System;
public class score : MonoBehaviour {
public Transform jugador;
public Text Score;
public Text highscore;
public Text scoreText;
private int currentscore = 0;
private float floa;
void Start() {
highscore.text = PlayerPrefs.GetInt("HighScore", 0).ToString();
}
private void SetHighScore() {
if (currentscore > PlayerPrefs.GetInt("HighScore", 0)) {
PlayerPrefs.SetInt("HighScore", currentscore);
}
}
private void Update () {
floa = jugador.position.z;
currentscore = (int)floa;
scoreText.text = currentscore.ToString();
highscore.text = PlayerPrefs.GetString ("HighScore").ToString();
}
}发布于 2020-11-30 14:54:37
highscore是有效的,但是当你在highscore.text上使用它时,你调用的是一个PlayerPrefs.GetString,但是Highscore实际上是一个整数!只需这样更改最后一行:
highscore.text = PlayerPrefs.GetInt("HighScore",0).ToString();应该没问题:D
发布于 2020-11-30 18:32:13
highscore.text = PlayerPrefs.GetString ("HighScore").ToString();
上面这行是错的,应该是
highscore.text = PlayerPrefs.GetInt("HighScore",0).ToString();
因为当你保存分数时,PlayerPrefs是整型的,而不是字符串。
https://stackoverflow.com/questions/65064977
复制相似问题