コード例 #1
0
    public void DecreaseHealth(int damage)
    {
        if (status.isDying || status.isDead)
        {
            return;
        }

        int reducedDamage = damageSystem.CalculateDamage(damage);

        currentHp = Mathf.Max(currentHp - reducedDamage, 0);
        //Debug.Log(gameObject.tag + "Current Hp is: " + currentHp);
        if (currentHp == 0)
        {
            status.isDying = true;
        }

        healthUi.UpdateHealth(maxHp, currentHp);
    }
コード例 #2
0
 public override void OnTouch(Collider collider)
 {
     if (frozen)
     {
         return;
     }
     if (liveMixin.IsAlive() && Time.time > timeLastBite + biteInterval)
     {
         Creature component = GetComponent <Creature>();
         if (component.Aggression.Value >= 0.1f)
         {
             GameObject target = GetTarget(collider);
             if (!playerDeathCinematic.IsCinematicModeActive())
             {
                 Player player = target.GetComponent <Player>();
                 if (player != null)
                 {
                     if (Time.time > timeCinematicAgain && player.CanBeAttacked() && player.liveMixin.IsAlive() && !player.cinematicModeActive)
                     {
                         float num = DamageSystem.CalculateDamage(biteDamage, DamageType.Normal, player.gameObject, null);
                         if (player.liveMixin.health - num <= 0f)
                         {
                             Invoke("KillPlayer", 2.5f);
                             playerDeathCinematic.StartCinematicMode(player);
                             attackSource.clip = cinematicClipPool.GetRandomClip();
                             attackSource.Play();
                             timeCinematicAgain = Time.time + 5f;
                             timeLastBite       = Time.time;
                             return;
                         }
                     }
                 }
                 LiveMixin liveMixin = target.GetComponent <LiveMixin>();
                 if (liveMixin == null)
                 {
                     return;
                 }
                 if (!liveMixin.IsAlive())
                 {
                     return;
                 }
                 if (liveMixin == Player.main.liveMixin)
                 {
                     if (!player.CanBeAttacked())
                     {
                         return;
                     }
                 }
                 if (!CanAttackTargetFromPosition(target))
                 {
                     return;
                 }
                 liveMixin.TakeDamage(GetBiteDamage(target));
                 attackSource.clip = biteClipPool.GetRandomClip();
                 attackSource.Play();
                 timeLastBite = Time.time;
                 creature.GetAnimator().SetTrigger("bite");
                 component.Aggression.Value -= 0.15f;
             }
         }
     }
 }