Beispiel #1
0
    /// <summary>
    /// Damage by the specified amt.
    /// </summary>
    /// <param name="amt">Amount to deduct from health.</param>
    public void Damage(int amt)
    {
        if (OnPlayerTryHit != null)
        {
            OnPlayerTryHit();
        }
        if (invincibility.IsOn() || amt <= 0)
        {
            return;
        }
        health -= amt;
        OnPlayerDamaged(amt);

        body.AddRandomImpulse(3f);
        HitDisable(HIT_DISABLE_TIME);
        FlashColor(Color.red);

        if (health <= 0 && OnPlayerWillDie != null)
        {
            OnPlayerWillDie();                  // for events that prevent the player's death
        }
        // Player Died
        if (health <= 0)
        {
            StartCoroutine(DieRoutine());
        }
        else
        {
            sound.RandomizeSFX(hurtSound);
        }
    }
Beispiel #2
0
    private IEnumerator HitDisableState(float time, float randomImpulse)
    {
        // Set properties
        hitDisabled    = true;
        body.ragdolled = true;
        body.AddRandomImpulse(randomImpulse);

        yield return(new WaitForSeconds(time));

        anim.CrossFade("default", 0f);
        hitDisabled    = false;
        body.ragdolled = false;
        ToMoveState();
        yield return(null);
    }