示例#1
0
    public void DecreaseHealth(float bulletDamage, string playersCurElement)
    {
        // Decrease enemy health if it wont die from damage
        if (e_CurHealth > gm.e_HealthDeath)
        {
            //Screen shake
            ScreenShakeInfo Info = new ScreenShakeInfo();
            Info.shakeMag          = gm.shakeMagHit;
            Info.shakeRou          = gm.shakeRouHit;
            Info.shakeFadeIDur     = gm.shakeFadeIDurHit;
            Info.shakeFadeODur     = gm.shakeFadeODurHit;
            Info.shakePosInfluence = gm.shakePosInfluenceHit;
            Info.shakeRotInfluence = gm.shakeRotInfluenceHit;

            ss.StartShaking(Info, .1f, 2);

            //Freeze the game for a split second
            gm.Freeze();

            // If player countered the enemy with their hit, take bonus damage
            if (playersCurElement == "Fire" && gm.e_IsEarth)
            {
                e_CurHealth -= bulletDamage + gm.fireDamage;

                // Play crit projectile audio
                FindObjectOfType <AudioManager>().Play("ProjectileHitCrit");

                // Play audio
                FindObjectOfType <AudioManager>().Play("ProjectileHit");
            }

            // If player countered the enemy with their hit, take bonus damage
            if (playersCurElement == "Water" && gm.e_IsFire)
            {
                e_CurHealth -= bulletDamage + gm.waterDamage;

                // Play crit projectile audio
                FindObjectOfType <AudioManager>().Play("ProjectileHitCrit");

                // Play audio
                FindObjectOfType <AudioManager>().Play("ProjectileHit");
            }

            // If player countered the enemy with their hit, take bonus damage
            if (playersCurElement == "Earth" && gm.e_IsWater)
            {
                e_CurHealth -= bulletDamage + gm.earthDamage;

                // Play crit projectile audio
                FindObjectOfType <AudioManager>().Play("ProjectileHitCrit");

                // Play audio
                FindObjectOfType <AudioManager>().Play("ProjectileHit");
            }

            // If there is no element counter, do regular damage
            if (playersCurElement == "Fire" && gm.e_IsWater)
            {
                e_CurHealth -= bulletDamage;
            }

            // If there is no element counter, do regular damage
            if (playersCurElement == "Fire" && gm.e_IsFire)
            {
                e_CurHealth -= bulletDamage;
            }

            // If there is no element counter, do regular damage
            if (playersCurElement == "Water" && gm.e_IsEarth)
            {
                e_CurHealth -= bulletDamage;
            }

            // If there is no element counter, do regular damage
            if (playersCurElement == "Water" && gm.e_IsWater)
            {
                e_CurHealth -= bulletDamage;
            }

            // If there is no element counter, do regular damage
            if (playersCurElement == "Earth" && gm.e_IsFire)
            {
                e_CurHealth -= bulletDamage;
            }

            // If there is no element counter, do regular damage
            if (playersCurElement == "Earth" && gm.e_IsEarth)
            {
                e_CurHealth -= bulletDamage;
            }

            // Play audio
            FindObjectOfType <AudioManager>().Play("ProjectileHit");
        }

        // If this object dies, and is not a boss
        if (e_CurHealth <= gm.e_HealthDeath && !isBoss)
        {
            //Play Death Audio
            FindObjectOfType <AudioManager>().Play("EnemyDeath");

            //Decrease enemy count
            gm.enemyCount--;

            //Decrease room enemy count
            room.GetComponent <Room>().roomEnemyCount--;

            //Kill enemy
            Destroy(gameObject);
        }

        // if the boss dies
        if (e_CurHealth <= gm.e_HealthDeath && isBoss && !isDead)
        {
            //Play Death Audio
            FindObjectOfType <AudioManager>().Play("BossDeath");

            //Trigger dialogue system
            bossDialogueReady = true;

            isDead = true;

            // set the animation to idle
            animator.SetInteger("EnemyBrain", 0);

            // set the rb of the enemy to kinematic. prevents it
            // being able to be pushed around by player
            rb.bodyType = RigidbodyType2D.Static;

            // turn off the element background
            elementBGAnimator.enabled = false;
            BGElement.GetComponent <SpriteRenderer>().sprite = null;

            rm.bossHealth.SetActive(false);
        }

        StartCoroutine("UpdateHealthBar");
    }