获得在Unity 5
问题描述:
错误
我收到此错误团结 “名为X的局部变量不能在此范围中声明”:获得在Unity 5
5.50f3 资产/脚本/ BaseClient/client.cs(14701, 12):错误CS0136:名为'text'的局部变量不能在此范围内声明,因为它会给'text'赋予不同的含义,'text'已用于'子'范围内以表示其他内容
这是一段代码:
case 126:
//String text = inStream.readString();
int frame = inStream.method435();
if (text.StartsWith("www."))
{
//openURL(text);
pktType = -1; return true;
}
if(text != null && frame != null)
{
updateStrings(text, frame);
sendFrame126(text, frame);
}
if (frame >= 18144 && frame <= 18244)
{
//clanList[frame - 18144] = text;
}
pktType = -1; return true;
答
错误只是让您知道您正在重复使用两个变量的同名:
int myVar = 0; //这个是全局的类
void开始() { int myVar = 20; //局部变量,同名=>问题 }
另一种情况是语句
if(condA)
{
int myResult = MethodA();
}
else
{
int myResult = MethodB();
}
内这可能是你所面临的是什么。无论是在每个小节给出一个不同的名称或获取变量的:
int myResult = -1;
if(condA)
{
myResult = MethodA();
}
else
{
myResult = MethodB();
}
这是你面对可能的。无论是在每个
情况下给予不同的名称126: \t \t \t \t //字符串文本= inStream.readString(); \t \t \t \t int frame = inStream.method435(); \t \t \t \t如果(text.StartsWith( “WWW”)){ \t \t \t \t \t //的OpenURL(文本); \t \t \t \t \t pktType = -1; \t \t \t \t \t return true; \t \t \t \t} \t \t \t \t如果(文字!= NULL &&帧!= NULL) \t \t \t \t { \t \t \t \t updateStrings(文本,帧); \t \t \t \t sendFrame126(文本,帧); \t \t \t \t} \t \t \t \t如果(帧> = 18144 &&帧
这不是如何提问。编辑你的问题,并将其添加到它。如果我是你,我真的里面client.cs添加整个代码,因为一个变量可能声明两次。 – Programmer
焦虑问题:我希望你没有一个包含100多个案例的switch-case语句 – TheDjentleman