Ejemplo n.º 1
0
        Worm GetPossibleWorm()
        {
            Worm worm         = null;
            var  peakCollider = GetComponent <CircleCollider2D>();

            // From all worms in the scene...
            foreach (Worm w in FindObjectsOfType <Worm>())
            {
                // Find the one that's inside our collider
                if (peakCollider.bounds.Contains(w.transform.position))
                {
                    worm = w;
                    break;
                }
            }
            return(worm);
        }
Ejemplo n.º 2
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;
        }