Ejemplo n.º 1
0
    public void TakeDamage(float damage, float damageMultiplier = 1.0f)
    {
        if (isAlive)
        {
            float damageTaken = damage * damageMultiplier;
            currentHealth -= damageTaken;
            healthBar.SetHealth(currentHealth);
            if (currentHealth > maxHealth)
            {
                currentHealth = maxHealth;
            }

            //show damage/heal numbers
            if (TextPopupsHandler)
            {
                Vector3 tempPos = transform.position;
                tempPos += TPOffset;
                TextPopupsHandler.ShowDamage(damageTaken, tempPos);
            }

            //hurt animation
            if (enAnimator != null && damage > 0) //took damage, not heal
            {
                Vector3 particleLocation = transform.position;
                Vector3 particleOffset   = particleLocation;
                particleOffset.y += .5f;
                HitEffectsHandler.ShowHitEffect(particleOffset);

                //enIsHurt = true;
                //enAnimator.SetTrigger("Hurt");
                if (!isAttacking)
                {
                    enAnimator.SetTrigger("enLightStun");
                }

                sr.material = mWhiteFlash; //flashing enemy sprite
                Invoke("ResetMaterial", .1f);
            }

            if (currentHealth <= 0)
            {
                Die();
            }
        }
    }
Ejemplo n.º 2
0
    public virtual void TakeDamage(float damage, float damageMultiplier = 1.0f, bool isCrit = false)
    {
        if (isAlive)
        {
            float damageTaken = damage * damageMultiplier;
            currentHealth -= damageTaken;
            healthBar.SetHealth(currentHealth);
            if (currentHealth > maxHealth)
            {
                currentHealth = maxHealth;
            }

            if (TextPopupsHandler)
            {
                Vector3 tempPos = transform.position;
                tempPos.y += TPOffset;
                TextPopupsHandler.ShowDamage(damageTaken, tempPos, isCrit);
                if (isCrit)// && screenshake != null)
                {
                    ScreenShakeListener.Instance.Shake();
                }
            }

            if (damage > 0)
            {
                Vector3 particleLocation = transform.position;
                particleLocation.y += hitEffectOffset;
                HitEffectsHandler.ShowHitEffect(particleLocation);

                if (!isAttacking && EnAnimator != null)
                {
                    EnAnimator.PlayHurt();
                }

                sr.material = mWhiteFlash;
                isHurt      = true;
                Invoke("ResetMaterial", .1f);
            }

            if (currentHealth <= 0)
            {
                Die();
            }
        }
    }
Ejemplo n.º 3
0
    public void TakeDamage(float damage, float damageMultiplier = 1.0f)
    {
        if (isAlive == true)
        {
            float damageTaken = damage * damageMultiplier;
            if (isBroken)
            {
                damageTaken *= 2f;
            }

            currentHealth -= damageTaken;
            healthBar.SetHealth(currentHealth);
            if (currentHealth > maxHealth)
            {
                currentHealth = maxHealth;
            }


            //temp knockback
            Vector3 tempLocation = TPOffsetObj.transform.position;

            //
            HitEffectsHandler.ShowHitEffect(tempLocation);
            //show damage/heal numbers
            if (TextPopupsHandler)
            {
                Vector3 tempPos = TPOffsetObj.transform.position;
                tempPos += TPOffset;
                if (isBroken) //crit damage, damage was multiplied, this is set when Boss is parried
                {
                    //
                    timeManager.DoFreezeTime(.1f);
                    TextPopupsHandler.ShowDamage(damageTaken, tempPos, true);
                }
                else
                {
                    TextPopupsHandler.ShowDamage(damageTaken, tempPos);
                }
            }

            //hurt animation
            if (enAnimator != null && damage > 0) //took damage, not heal
            {
                enIsHurt = true;
                enAnimator.SetTrigger("Hurt");

                sr.material = mWhiteFlash; //flashing enemy sprite
                Invoke("ResetMaterial", .1f);
            }

            if (isBroken)
            {
                enAnimator.SetTrigger("StunHits");
                ScreenShakeListener.Instance.Shake();

                if (particleHits)
                {
                    if (playerToRight)
                    {
                        Instantiate(stunLParticlePrefab, tempLocation, Quaternion.identity);
                    }
                    else
                    {
                        Instantiate(stunRParticlePrefab, tempLocation, Quaternion.identity);
                    }
                }
            }

            if (currentHealth <= 0)
            {
                Die();
            }
        }
    }