My Dying Animation

I used this code to disable both colliders on my character when he dies:

Collider2D colliders = GetComponents();

    foreach (Collider2D collider in colliders)
     {
        collider.enabled = false;

    } 

The effect is cool. The he goes into his death animation and then plummets off screen…

Here’s the updated code with the deathKick. I’m happy with it. It is the Super Mario Bros. death animation effect.

void Die()

{

if (myBodyCollider.IsTouchingLayers(LayerMask.GetMask("Enemy")))

{

    isAlive = false;

    myAnimator.SetTrigger("Dying");

    myRigidbody.velocity = deathKick;

    myRigidbody.velocity = new Vector2(0f, myRigidbody.velocity.y);

    Collider2D[] colliders = GetComponents<Collider2D>();

    foreach (Collider2D collider in colliders)

    {

        collider.enabled = false;

    }

}

}

2 Likes

Privacy & Terms