Example #1
0
 private void RefreshHealthBar()
 {
     if (healthBar != null)
     {
         healthBar.ChangeValue(health, maxHealth);
     }
 }
Example #2
0
    public void TakeDamage(int damage)
    {
        _health -= damage;
        _hpBar.ChangeValue((float)_health / (float)_maxHealth);

        if (_health <= 0)
        {
            StartCoroutine(OnDeath());
        }
        else
        {
            StartCoroutine(OnHit());
        }
    }
Example #3
0
        public virtual void Damage(float damage)
        {
            health -= damage;
            healthBar.ChangeValue(health / maxHealth);

            if (health <= 0)
            {
                health = 0;
                Console.WriteLine("Enemy is dead");
                Die();
            }
            else
            {
                Console.WriteLine("Enemy at {0} health", health);
            }
        }
    public override void OnReceiveDamage(Character source, int damage)
    {
        Vector2 sourcePosition = source.gameObject.transform.position;
        Vector2 selfPosition   = gameObject.transform.position;

        Vector2 force = new Vector2(sourcePosition.x - selfPosition.x, sourcePosition.y - selfPosition.y).normalized;

        //Debug.Log(force);

        body.AddForce(-force * 5.0f, ForceMode2D.Impulse);
        //Debug.Log("Enemy received damage");

        foreach (SpriteRenderer child in hpBar.GetComponentsInChildren <SpriteRenderer>())
        {
            child.enabled = true;
        }
        hpInfo.ChangeValue(hp, maxHP);
    }