Esempio n. 1
0
    // Apply damage to player or enemy
    public void ApplyDamage(float damage, bool knockDown)
    {
        if (characterDied)
        {
            return;
        }

        // Applying health damage
        health -= damage;

        //display health UI
        if (is_Player)
        {
            health_UI.DisplayHealth(health);
        }

        // If character has died
        if (health <= 0f)
        {
            // Play death animation
            animationScript.Death();

            // Detect the character has died
            characterDied = true;

            // If it's the player deactivate the enemy script
            // so the enemy stops trying to fight
            if (is_Player)
            {
                GameObject.FindWithTag(Tags.ENEMY_TAG).GetComponent <EnemyMovement>().enabled = false;
            }

            return;
        }

        // If enemy has taken damage
        if (!is_Player)
        {
            if (knockDown)
            {
                // If knocked down, play knock down script
                if (Random.Range(0, 2) > 0)
                {
                    animationScript.KnockDown();
                }

                else
                {
                    // If not knocked down, play hit animation
                    if (Random.Range(0, 3) > 1)
                    {
                        animationScript.Hit();
                    }
                }
            } // Randomized so the hit animation isn't always played or the
              //character isn't always knocked down with the left hand, right foot, etc
        }
    }
    public void ApplyDamage(float damage, bool knockDown)
    {
        if (characterDied)
        {
            return;
        }
        health -= damage;

        if (is_Player)
        {
            healthUI.DisplayHealth(health);
        }


        if (health <= 0f)
        {
            mycharacterAnimationsScript.Death();
            characterDied = true;

            if (is_Player)
            {
                GameObject.FindGameObjectWithTag(Tags.ENEMY_TAG).GetComponent <EnemyMovements>().enabled = false;
            }

            else
            {
            }
            return;
        }

        if (!is_Player)
        {
            if (knockDown)
            {
                if (Random.RandomRange(0, 2) > 0)
                {
                    mycharacterAnimationsScript.KnockDown();
                    print("Knock Down");
                }
            }

            else
            {
                if (Random.RandomRange(0, 3) > 1)
                {
                    mycharacterAnimationsScript.Hit();
                    print("Hit");
                }
            }
        }
    }
Esempio n. 3
0
    public void ApplyDamage(float damage, bool knockDown)
    {
        if (characterDied)
        {
            return;
        }

        health -= damage;

        // display health UI
        if (is_Player)
        {
            health_UI.DisplayHealth(health);
        }

        if (health <= 0f)
        {
            animationScript.Death();
            characterDied = true;

            // if is player deactivate enemy script
            if (is_Player)
            {
                GameObject.FindWithTag(Tags.ENEMY_TAG)
                .GetComponent <EnemyMovement>().enabled = false;
            }

            return;
        }

        if (!is_Player)
        {
            if (knockDown)
            {
                if (Random.Range(0, 2) > 0)
                {
                    animationScript.KnockDown();
                }
            }
            else
            {
                if (Random.Range(0, 3) > 1)
                {
                    animationScript.Hit();
                }
            }
        } // if is player
    }     // apply damage
Esempio n. 4
0
    public void ApplyDamage(float damage, bool knockDown)
    {
        if (characterDead)
        {
            return;
        }

        health -= damage;

        if (isPlayer)
        {
            healthUI.DisplayHealth(health);
        }

        if (health <= 0f)
        {
            animationScript.Death();
            characterDead = true;

            if (isPlayer)
            {
                GameObject.FindWithTag(Tags.ENEMY_TAG).GetComponent <EnemyMovement>().enabled = false;
                WaveCounter.instance.GameOver();
            }

            return;
        }

        if (!isPlayer)
        {
            if (knockDown)
            {
                if (Random.Range(0, 2) > 0)
                {
                    animationScript.KnockDown();
                }
                else
                {
                    if (Random.Range(0, 3) > 1)
                    {
                        animationScript.Hit();
                    }
                }
            }
        }
    }
Esempio n. 5
0
    public void ApplyDamage(float damage, bool knockDown)
    {
        if (invulnerable)
        {
            return;
        }

        if (health <= 0f && !characterDied)
        {
            if (animationScript)
            {
                animationScript.Death();
            }
            else
            {
                Destroy(gameObject, 1f);
            }

            characterDied = true;

            if (is_Player)
            {
                GameObject.FindWithTag(Tags.ENEMY_TAG)
                .GetComponent <EnemyMovement>().enabled = false;
            }

            else
            {
                FindObjectOfType <GameManager>()?.AddScore(GetComponent <EnemyStats>().scoreValue);
            }


            return;
        }
        else if (!characterDied && health > 0f)
        {
            health -= damage;


            if (is_Player)
            {
                if (health_UI)
                {
                    health_UI.DisplayHealth(health, maxHealth);
                }
            }

            else if (!is_Player)
            {
                if (is_Boss)
                {
                    if (health_UI)
                    {
                        health_UI.DisplayHealthUsingScale(health, maxHealth);
                    }
                }

                if (knockDown)
                {
                    if (Random.Range(0, 2) > 0)
                    {
                        animationScript.KnockDown();
                    }
                }
                else
                {
                    if (Random.Range(0, 3) > 1)
                    {
                        animationScript.Hit();
                    }
                }
            }
        }
        else if (characterDied && health <= 0f)
        {
            if (animationScript)
            {
                animationScript.Death();
            }
            else
            {
                Destroy(gameObject, 1f);
            }
            if (is_Player)
            {
                GameObject.FindWithTag(Tags.ENEMY_TAG)
                .GetComponent <EnemyMovement>().enabled = false;
            }

            else
            {
                FindObjectOfType <GameManager>()?.AddScore(GetComponent <EnemyStats>().scoreValue);
            }


            return;
        }
    }