Ejemplo n.º 1
0
        IEnumerator EatingSequence()
        {
            Worm worm = GetPossibleWorm();

            // Play the In animation and wait
            animator.ChangeAnimation(animEatIn);
            yield return(animator.PlayAndPauseAt());

            if (worm)
            {
                // Hide the worm
                worm.GetEaten();
                // Play the Mid animation
                animator.ChangeAnimation(animEatMid);
                animator.SetFrame(0);
                animator.Play();
                float t = Time.time;
                // Wait
                while (Input.GetButton(eatButton) && Time.time - t < 1)         // while we hold the button
                {
                    yield return(null);
                }
                // Wait until the middle animation ends before playing the next (prince of persia style)
                while (animator.CurrentFrame != 0)
                {
                    yield return(null);
                }
            }
            animator.SetFrame(0);
            // Play the Out animation
            animator.ChangeAnimation(animEatOut);
            yield return(animator.PlayAndPauseAt());

            // Go back to Idle
            animator.ChangeAnimation(animationIdle);
            currentEatingSequence = null;
        }