Unity3d 在for循环中使用if语句 用于(int i=0;i
问题是,我先调用for循环,然后在start方法中设置maxlevelreached,很抱歉,这里没有程序员。你会遇到什么错误?不是Unity3d 在for循环中使用if语句 用于(int i=0;i,unity3d,Unity3d,问题是,我先调用for循环,然后在start方法中设置maxlevelreached,很抱歉,这里没有程序员。你会遇到什么错误?不是maxlvereached类型bool吗?你检查了maxlvereached的值吗?不,maxlvereached是整数,我是从playerpref获取的,我没有任何error,它只是不能像AntiHeadshot所说的那样工作,Debug.Log值,比如Debug.Log((i+1)+“|”+maxlreached)。另外,尝试将组件存储为GetComponent
maxlvereached
类型bool吗?你检查了maxlvereached
的值吗?不,maxlvereached是整数,我是从playerpref获取的,我没有任何error,它只是不能像AntiHeadshot所说的那样工作,Debug.Log
值,比如Debug.Log((i+1)+“|”+maxlreached)
。另外,尝试将组件存储为GetComponent方法是非常昂贵的。您只是在使用i+1
那么为什么不将循环更改为for(int i=1;i>
for (int i=0; i<=83; i++)
{
GameObject btns = Instantiate (buttoneg.gameObject) as GameObject;
btns.gameObject.GetComponent<LevelButton> ().levelNo = i + 1;
if(btns.gameObject.GetComponent<LevelButton>().levelNo<maxlvlreached)
{
btns.gameObject.GetComponent<LevelButton>().button.image.color=Color.green;
}
}