Beispiel #1
0
    //Creates the damage popup
    public static Sidescrolling_DamagePopup Create(Vector3 position, int damage, bool isCriticalHit)
    {
        Transform damagePopupTransform = Instantiate(GameAssets.i.prefabDamagePopup, position, Quaternion.identity);

        Sidescrolling_DamagePopup damagePopup = damagePopupTransform.GetComponent <Sidescrolling_DamagePopup>();

        damagePopup.Setup(damage, isCriticalHit);

        return(damagePopup);
    }
Beispiel #2
0
    public void TakeDamage(int damage)
    {
        //this counter is mainly for the necromancer boss
        hitCount++;

        //for playing sounds
        hurt.GetComponent <AudioSource>().Play();

        bool isCriticalHit = Random.Range(0, 100) < 30;

        if (isCriticalHit)
        {
            damage = (int)(damage * 1.53f);
        }
        Sidescrolling_DamagePopup.Create(this.transform.position, damage, isCriticalHit);

        currentHealth -= damage;

        healthbar.SetHealth(currentHealth, maxHealth);

        //play hurt animation
        animator.SetTrigger("Hurt");

        //this is used for other scripts to know if the enemy is currently being hurt
        isHurt = true;
        if (isDead)
        {
            this.GetComponent <Rigidbody2D>().velocity = new Vector2(0f, 0f);
        }

        if (currentHealth <= 0)
        {
            Die();
        }
        else
        {
            StartCoroutine(HurtDelay(0.5f));
        }
    }