Esempio n. 1
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.collider.gameObject.name == "Barrel" && !isDead)
        {
            isDead = true;

            // Play the death animation
            if (anim != null)
            {
                anim.SetBool("Death", true);
            }

            // Set Mario's velocity to 0, and increase his mass so that the barrels can't push him around :)
            GetComponent <Rigidbody2D>().velocity = Vector2.zero;
            GetComponent <Rigidbody2D>().mass     = 1000;

            // Stop the background music & walking sound, and play the death sound effect instead
            soundEffectPlayer.PlayWalkEffect(false);
            soundEffectPlayer.StopBackgroundMusic();
            soundEffectPlayer.PlayDieEffect();

            // Don't spawn any more barrels
            if (barrelSpawner != null)
            {
                barrelSpawner.Stop();
            }

            // Show the Game Over sprite
            if (gameOverSprite != null)
            {
                gameOverSprite.enabled = true;
            }
        }
    }
Esempio n. 2
0
    void SwitchToState(State nextState)
    {
        if (currentState == nextState)
        {
            return;
        }

        if (nextState == State.Idle || nextState == State.Walking)
        {
            climbingLadder = null;
            GetComponent <Rigidbody2D>().isKinematic = false;
        }
        else if (nextState == State.Jumping)
        {
            shouldJump = true;
            soundEffectPlayer.PlayWalkEffect(false);
            soundEffectPlayer.PlayJumpEffect();
        }
        else if (nextState == State.Climbing)
        {
            GetComponent <Rigidbody2D>().isKinematic = true;
        }
        else if (nextState == State.Dead)
        {
            // Play the death animation
            if (anim != null)
            {
                anim.SetBool("Death", true);
            }

            // Set Mario's velocity to 0, and increase his mass so that the barrels can't push him around :)
            GetComponent <Rigidbody2D>().velocity = Vector2.zero;
            GetComponent <Rigidbody2D>().mass     = 1000;

            // Stop the background music & walking sound, and play the death sound effect instead
            soundEffectPlayer.PlayWalkEffect(false);
            soundEffectPlayer.StopBackgroundMusic();
            soundEffectPlayer.PlayDieEffect();

            // Don't spawn any more barrels
            if (barrelSpawner != null)
            {
                barrelSpawner.Stop();
            }

            // Show the Game Over sprite
            if (gameOverSprite != null)
            {
                gameOverSprite.enabled = true;
            }
        }

        currentState = nextState;
    }