示例#1
0
    //apply final damage calculations made in CalculateDamageTime ~ need to consider this design as well for enemies!
    private void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.tag.Equals("Laser"))
        {
            //calculate final damage laser has dealt to this gameObject
            {
                isReceivingDamage = false;
                PlayerDPS dps = collision.GetComponent <PlayerDPS>();
                //adjust total damage received based on the time the laser spent on this boss body part
                float timeSpent           = Mathf.Clamp(elapsedDamageTime, 0f, laserCD.abilityTimer.duration);
                float totalDamageReceived = dps.DamagePerFrame * (1f / dps.frequency) * timeSpent;

                Debug.Log(gameObject.name + " totalDamageReceived: " + totalDamageReceived);

                if (hp - totalDamageReceived < 0f)
                {
                    bm.ApplyDamage(hp);
                    hp = 0f;
                }
                else
                {
                    bm.ApplyDamage(totalDamageReceived);
                    hp -= totalDamageReceived;
                }
            }
        }
    }