【发布时间】:2013-01-22 23:53:17
【问题描述】:
我有一个在 NGUI 中制作简单菜单动画的功能。 好像很好用,但是当我进入游戏然后返回菜单时,该功能无法正常工作。
IEnumerator MenuTransition (GameObject panelOut, GameObject panelIn) {
foreach (Transform child in panelOut.transform)
{
if(child.gameObject.collider != null)
{
child.gameObject.collider.enabled = false;
UIButton [] buttons = child.GetComponents<UIButton>();
foreach(UIButton b in buttons) b.UpdateColor(true, true);
}
child.gameObject.animation.Play("MenuTransitionOff");
}
Debug.Log("time: "+animTime);
//yield return new WaitForSeconds(animTime);
Debug.Log("ini");
foreach (Transform child in panelIn.transform)
{
UIButton [] buttons = child.GetComponents<UIButton>();
foreach(UIButton b in buttons) b.UpdateColor(true, true);
child.gameObject.animation.Play("MenuTransitionOn");
}
//yield return new WaitForSeconds(animTime);
foreach (Transform child in panelIn.transform)
{
if(child.gameObject.collider != null)
{
child.gameObject.collider.enabled = true;
}
}
Debug.Log("3");
yield return null;
Debug.Log("4");
}
这个函数从另一个分配给按钮 onclick 事件的函数中调用(使用 NGUI)。
void OnMainMatch () {
StartCoroutine(MenuTransition(mainPanel, matchPanel));
}
由于未注释收益,应用程序似乎在第一个收益时崩溃,之后不再出现日志,但即使我评论两个收益并在最后添加一个,我也没有动画并且按钮变得无响应。在最后一种情况下,打印 4。这只发生在进入游戏并返回菜单后,而不是第一次执行菜单时。 我也调试过动画时间,不到一秒,所以是正确的。 我真的不知道在哪里寻找错误。知道去哪里找吗?
【问题讨论】:
-
当它崩溃时,它究竟是如何做到的?你有什么异常吗?
标签: c# unity3d coroutine yield-return ngui