Exemplo n.º 1
0
    public void TakeDamage(int damage)
    {
        if (health > 0)
        {
            SoundManagerScript.PlaySound("BaccyHurt");
        }

        health -= damage;

        if (health <= 0) // If enemy health is depleted, enemy dies
        {
            if (enemyType == "Patrol")
            {
                // Prevent damage to player
                BaccyPatrol bp = gameObject.GetComponent <BaccyPatrol>();
                bp.speed = 0f;
            }

            enemyCol.enabled = false;

            // Invoke Death
            SoundManagerScript.PlaySound("Death");
            anim.SetTrigger("Death");
            Invoke("Die", 0.6f);
        }
    }
Exemplo n.º 2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.name == "Ery")
        {
            player    = collision.GetComponent <CharacterController2D>();
            baccyBody = GetComponent <BaccyPatrol>();

            // Check if character is vulnerable
            if (player.invulnerabilityCount <= 0)
            {
                SoundManagerScript.PlaySound("EryHurt");
                Animator anim = player.GetComponent <Animator>();
                anim.SetTrigger("Hurt");
                player.knockBackCount       = player.knockBackLength;
                player.CharacterLives      -= 1;
                player.invulnerabilityCount = 1f;
            }
            else if (player.CharacterLives < 1) // Only knockback if character is alive
            {
                baccyBody.speed = 0f;           // Stop baccy from moving

                player.knockBackCount       = 0;
                player.CharacterLives      -= 1;
                player.invulnerabilityCount = 1f;
            }

            if (collision.transform.position.x < transform.position.x)
            {
                player.knockBackFromRight = true;
            }
            else
            {
                player.knockBackFromRight = false;
            }
        }
    }