0

I have a function to make a simple menu animation in NGUI. It seems to work great, but when I go ingame and then return to menu, the function is not working properly.

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");
}

And this function quets clled from another one that's assigned to a button onclick event (using NGUI).

void OnMainMatch () {
    StartCoroutine(MenuTransition(mainPanel, matchPanel));
}

With the yields uncommented, the app seem to crash at the first one and no more logs appear after, but even if I comment the two yields and add one at the end, I get no animation and the buttons become irresponsive. In that last case, 4 gets printed. This occurs only after getting ingame and returning to menu, not the first time the menu is executed. I have also debugged the animation time and it's less than a second, so it's correct. I really have no clue on where to look for the error. Any idea on where to look for?

Kay
  • 12,918
  • 4
  • 55
  • 77

1 Answers1

0

I had the same kind of problem with NGUI's OnClick and coroutines, and it appeared because the OnClick-button was set inactive after calling the StartCoroutine. This causes that the iteration of the coroutine is exterminated, because it is the OnClick-object that manages the coroutine. Not sure if this is the same problem though.

Tim
  • 1