[英]Error CS0029: Cannot implicitly convert type 'int' to 'string'
I am creating a game in unity but im getting the error:我正在统一创建游戏,但出现错误:
error CS0029: Cannot implicitly convert type 'int' to 'string'.错误 CS0029:无法将类型“int”隐式转换为“string”。
Does anyone know the awnser?有谁知道awser吗?
public Text text;
int max;
int min;
int guess;
void Start () {
text.text = ("Pick a number in your head between " + min);
text.text = + max;
text.text = (" , but dont tell me!");
max = 1000;
min = 1;
guess = 500;
}
Try this:尝试这个:
public Text text;
int max;
int min;
int guess;
void Start () {
max = 1000;
min = 1;
guess = 500;
text.text = ("Pick a number in your head between " + min.ToString());
text.text += max.ToString();
text.text += (" , but dont tell me!");
}
But there is a better and more optimized way to concatenate strings, try this:但是有一种更好、更优化的方法来连接字符串,试试这个:
public Text text;
int max;
int min;
int guess;
void Start () {
max = 1000;
min = 1;
guess = 500;
text.text = string.Format("Pick a number in your head between {0} and {1}, but dont tell me!", min.ToString(), max.ToString());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.