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

            Vector3 changeLocation = GetComponent<Transform>().position;

            Vector3 tempLocation = changeLocation;
            //tempLocation.y += .0f; //y offset
            if(player.position.x > transform.position.x) //player to right of enemy
            {
                Instantiate(HitToLeft, tempLocation, Quaternion.identity);
            }
            else
            {
                Instantiate(HitToRight, tempLocation, Quaternion.identity);
            }

            //Instantiate(HitEffect, tempLocation, Quaternion.identity);
            HitEffectsHandler.ShowHitEffect(tempLocation);

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

            //show damage/heal numbers
            if (TextPopupsPrefab)
            {
                Vector3 tempPos = transform.position;
                tempPos += TPOffset;
                TextPopupsHandler.ShowDamage(damageTaken, tempPos);
            }
            
            //hurt animation
            if (enAnimator != null)
            {
                enAnimator.SetTrigger("Hurt");
            }
        
            if (currentHealth <= 0)
            {
                Die();
            }
        }
    }
Esempio 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();
            }
        }
    }
Esempio n. 3
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();
            }
        }
    }
Esempio n. 4
0
    public void TakeDamage(float damage, bool unBlockable = false)
    {
        if (isAlive)
        {
            if (currentHealth > 0)
            {
                if (animator.GetBool("isRolling")) //damage dodged
                {
                    damage = 0;
                    //xpPopups.ShowDodge(transform.position); //xpPopups uses a static animation instead of the number animation
                }
                if (!unBlockable)
                {
                    if (IsShieldBashing)
                    {
                        damage = 0;
                        xpPopups.ShowText(transform.position, "Blocked");
                    }
                }
                currentHealth -= (damage);
                healthBar.SetHealth(currentHealth);
                if (damage > 0)
                {
                    Vector3 tempPos = transform.position;
                    tempPos += TPOffset; //damage pop up
                    TextPopupsHandler.ShowDamage(damage, tempPos);

                    if (animator.GetBool("isAttacking") == false)
                    {
                        animator.SetTrigger("Hurt");
                    }

                    FlashMaterial();
                    //GetKnockback(true); //
                    Invoke("ResetMaterial", .1f);
                }
            }
            //hurt animation
            if (currentHealth <= 0)
            {
                Die();
            }
        }
    }
Esempio n. 5
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();
            }
        }
    }