Exemple #1
0
    public void HurtPlayer(float amount)
    {
        if (isInvincible)
        {
            return;
        }

        hp.ChangeHealth(-1 * amount);

        //Update HP bar fill (100%-0% based on percentage of max health) and color (green at 100%, yellow at 50%, red at 0%)
        hpBar.fillAmount = hp.Health / hp.MaxHealth;
        hpBar.color      = new Color((1 - Mathf.Max(0f, hpBar.fillAmount * 2 - 1)) * 0.8f, Mathf.Min(1f, hpBar.fillAmount * 2) * 0.8f, 0);
    }
    void OnTriggerEnter2D(Collider2D col)
    {
        if (tagsToIgnore.Contains(col.gameObject.tag) || col.isTrigger)
        {
            return;
        }

        if (col.CompareTag("Player"))
        {
            col.gameObject.GetComponent <PlayerControllerScript>().HurtPlayer(dmgAmount);
        }
        else
        {
            EntityHealth health = col.gameObject.GetComponent <EntityHealth>();
            if (health != null)
            {
                health.ChangeHealth(-1 * dmgAmount);
            }
        }

        Destroy(gameObject);
    }
Exemple #3
0
 private void DealDamage(EntityHealth _entityHealth, int _damage)
 {
     _entityHealth.ChangeHealth(_damage);
 }