【发布时间】:2015-12-01 12:58:16
【问题描述】:
我想获取 int 参数并将其保存到 playerprefs 然后获取它并将其更改为字符串并显示为字符串,但是当我使用 ToString();有错误:不能为 a=b 隐式转换类型 string' toint';
C# 统一
公共int a;
公共字符串 b;
{
car = GameObject.Find ("mastergame").GetComponent<master> ().carr;
if (car == 1) {
busted = GameObject.Find ("1").GetComponent<ruchauta1> ().busted;
gameover = GameObject.Find ("1").GetComponent<ruchauta1> ().gameover;
if (gameover == false && busted == false) {
scoree.text = "" + score;
}
if (gameover == true || busted == true) {
if(score>bestscore){
bestscore=score;
PlayerPrefs.SetInt("bestscore",bestscore);}
score=0;
PlayerPrefs.SetInt("score",score);
}
} else {
busted = GameObject.Find ("Audi").GetComponent<ruchauta> ().busted;
gameover = GameObject.Find ("Audi").GetComponent<ruchauta> ().gameover;
if (gameover == false && busted == false) {
scoree.text = "" + score;
}
if (gameover == true || busted == true) {
if(score>bestscore){
bestscore=score;
PlayerPrefs.SetInt("bestscore",bestscore);
a=PlayerPrefs.GetInt("bestscore",bestscore);}
score=0;
PlayerPrefs.SetInt("score",score);
}
}
a.ToString ();
a = b;
bestscoree.text = b;
}
void Score(){
car = GameObject.Find ("mastergame").GetComponent<master> ().carr;
if (car == 1) {
busted = GameObject.Find ("1").GetComponent<ruchauta1> ().busted;
gameover = GameObject.Find ("1").GetComponent<ruchauta1> ().gameover;
if (gameover == false && busted == false) {
score+=5;
PlayerPrefs.SetInt("score",score);
}
} else {
busted = GameObject.Find ("Audi").GetComponent<ruchauta> ().busted;
gameover = GameObject.Find ("Audi").GetComponent<ruchauta> ().gameover;
if (gameover == false && busted == false) {
score+=5;
PlayerPrefs.SetInt("score",score);
}
}
【问题讨论】:
-
您在这里使用什么平台和语言库?在我看来可疑的是
a.ToString ();,紧随其后的是a = b;。假设a.ToSTring ();实际更改了a,那么所做的任何更改都将被a = b覆盖。 -
如果我删除 a=b,写 bestscoree.text = a;还是有这个错误。
标签: tostring