【问题标题】:problems with yield in unity统一产量问题
【发布时间】: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


【解决方案1】:

我在使用 NGUI 的 OnClick 和协程时遇到了同样的问题,它出现是因为在调用 StartCoroutine 后 OnClick 按钮被设置为非活动状态。这导致协程的迭代被消灭,因为管理协程的是 OnClick 对象。不知道这是否是同一个问题。

【讨论】:

    猜你喜欢
    • 2014-05-08
    • 1970-01-01
    • 2011-04-06
    • 2021-07-12
    • 2012-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-01
    相关资源
    最近更新 更多