Esempio n. 1
0
    private void TakeHit(MakeDamage damageMaker, Transform other)
    {
        if (isDead)
        {
            return;
        }

        int resistance = stats.Defence;

        if (isPlayer)
        {
            Stuff head  = playerEquipement.head;
            Stuff torso = playerEquipement.torso;
            Stuff boots = playerEquipement.boots;

            if (head != null)
            {
                resistance += head.GetComponent <Stats>().Defence;
            }
            if (torso != null)
            {
                resistance += torso.GetComponent <Stats>().Defence;
            }
            if (boots != null)
            {
                resistance += boots.GetComponent <Stats>().Defence;
            }
        }

        stats.Life = damageMaker.isKiller ? 0 : Mathf.Max(0, stats.Life - (damageMaker.damage - resistance));

        currentHealth = stats.Life;

        if (!isPlayer)
        {
            LifeHud.GetComponent <LifeHud>().SetLife((float)stats.Life / (float)stats.MaxLife);
        }
        else
        {
            PlayerLifeHud.SetLife(stats.MaxLife, stats.Life);
        }

        if (Hit != null)
        {
            Hit(other);
        }

        if (currentHealth == 0)
        {
            isDead = true;
            if (!isPlayer)
            {
                LifeHud.gameObject.SetActive(false);
            }
            if (Die != null)
            {
                Die();
            }
        }
    }
Esempio n. 2
0
 // Use this for initialization
 void Start()
 {
     instance = this;
 }