我可以在代码的第一部分正确地调用它,它被构建到if else语句的长列表中。
if (Ten < 0) {
Ten = x;
long y = System.Int64.Parse (One + "" + Two + ""//... code continues);
print ("Press Tab to confirm to play with " + y + ".");
ChosenNum ();
} else if (Ten > -1) {
print ("Press Tab to confirm to play with " + y + ".");
}
在下面的函数之后的代码中,它不会调用long y。
void ChosenNum ()
{
if (Input.GetKeyDown (KeyCode.Tab)) {
print ("You have chosen " + y);
StartGame2 ();
}
}
如果我指定long y,我想在函数之后和函数中调用代码中的long y;在课堂开始时它与我的课程冲突;例如,创建一个长w将导致需要额外的代码,但是想要找到一个解决方案而不这样做。
答案 0 :(得分:0)
你为什么不这样做:
void ChosenNum (long value)
{
if (Input.GetKeyDown (KeyCode.Tab)) {
print ("You have chosen " + value);
StartGame2 ();
}
}
然后叫它:
if (Ten < 0) {
Ten = x;
long y = System.Int64.Parse (One + "" + Two + ""//... code continues);
print ("Press Tab to confirm to play with " + y + ".");
ChosenNum (y);//pass it here, this is my change
} else if (Ten > -1) {
print ("Press Tab to confirm to play with " + y + ".");
}