Search Unity

Perform action after animation - screen slide in/out animation

Discussion in 'Animation' started by Deleted User, Mar 25, 2015.

  1. Deleted User

    Deleted User

    Guest

    Hey everyone,

    I've worked with Unity for a bit now, but I haven't really done much with animation/UI.

    I'm currently working on a game and I wanted a screen to slide in/out similar to how it would on an iOS app (from the bottom up).

    I looked up tutorials and worked off of them. I actually copied Unity's ScreenManager class from their tutorial and worked from that.

    I have 5 states and two variables (Prepare and Open):

    Start - default state used, so that no animation is played on start - kind of funky as I need a mock animation as empty animation still takes some time.
    when Prepare -> True
    Prepare - changes anchor to bottom and puts screen just under main screen
    when Open -> True
    Open - moves screen up over main screen
    when Open -> False
    Close -reverse of Open
    when Prepare -> False
    Unprepare - reverse of Prepare

    The problem is with the Close animation/state. After the close animation finishes, I want to send the screen to the back (as first sibling in hierarchy). However, the screen gets sent to the back before the animation is finished.

    I attached the whole file for reference, but the problem is around here:

    IEnumerator ClosePanelDelayed (Animator anim)
    {
    boolclosedStateReached = false;
    boolwantToClose = true;
    while (!closedStateReached && wantToClose) {
    if (!anim.IsInTransition (0))
    closedStateReached = anim.GetCurrentAnimatorStateInfo (0).IsName (k_CloseStateName);

    wantToClose = !anim.GetBool (m_OpenParameterId);

    yield return new WaitForEndOfFrame ();
    }

    if (wantToClose) {
    anim.SetBool (m_PrepareParameterId, false);
    StartCoroutine (DisablePanelDelayed (anim));
    anim.transform.SetAsFirstSibling ();
    }
    }

    I have debugged the code, but all the conditions I use to attempt to test if the animation is finished end up being reached early and the screen disappears in the middle of the closing animation.
     

    Attached Files:

    Last edited by a moderator: Mar 25, 2015