示例#1
0
 public override void TakeDamage(Transform thingThatHitYou, float pushTime, float pushForce, float damage, bool display = true)
 {
     EnableEnemyStateUI();
     if (pushTime > 0)
     {
         EnemyState.MovementState = CharacterMovementState.Stunned;
     }
     LoseHealth(damage, display);
     if (transform.gameObject.activeInHierarchy)
     {
         if (thingThatHitYou && pushForce > 0)
         {
             Vector2 difference = transform.position - thingThatHitYou.position;
             difference = difference.normalized * pushForce * (1 - SlowTimeCoefficient);
             body.AddForce(difference, ForceMode2D.Impulse);
         }
         if (BlinkOnHit)
         {
             BlinkOnHit.Blink(spriteRenderer);
         }
         if (animator && animator.parameters.Any(c => c.name == "Hit"))
         {
             animator.SetTrigger("Hit");
         }
         if (pushTime > 0)
         {
             StartCoroutine(Knockback(body, pushTime));
         }
     }
 }
示例#2
0
    public override void TakeDamage(Transform thingThatHitYou, float pushTime, float pushForce, float damage, bool display = true)
    {
        if (PlayerState.MovementState == CharacterMovementState.Dashing)
        {
            rigidBody.velocity        = Vector2.zero;
            PlayerState.MovementState = CharacterMovementState.Idle;
            MoveSpeed = defaultSpeed;
        }

        PlayerState.MovementState = CharacterMovementState.Stunned;
        if (thingThatHitYou)
        {
            Vector2 difference = transform.position - thingThatHitYou.position;
            difference = difference.normalized * pushForce;
            rigidBody.AddForce(difference, ForceMode2D.Impulse);
        }
        PlayerHealth.LoseHealth(damage, display);
        blinkOnHit.Blink(playerSpriteRenderer);
        if (PlayerHealth.Health.CurrentHealth > 0)
        {
            StartCoroutine(KnockbackCo(rigidBody, pushTime, damage));
        }
        else
        {
            this.gameObject.SetActive(false);
        }
    }