Example #1
0
 public void TakeDamage(int damage)
 {
     if (damage > 0)
     {
         if ((health - damage) < 0)
         {
             health = 0;
             SetDeathAnimation();
             return;
         }
         else
         {
             health -= damage;
         }
     }
     enemyKnockback.ApplyKnockBack(ref enemyRigidBody);
 }
    private void Move()
    {
        if (isGrounded)
        {
            Vector3 targetVelocity = new Vector2(horizontalMovement * PlayerManager.Instance.stats.playerRunSpeed, PlayerManager.Instance.playerRigidBody.velocity.y);

            if (knockbackManager.knockbackCount <= 0)
            {
                PlayerManager.Instance.playerRigidBody.velocity = targetVelocity;
            }
            else
            {
                knockbackManager.ApplyKnockBack(ref PlayerManager.Instance.playerRigidBody);
            }
        }
        else
        {
            Vector3 targetVelocity = new Vector2(horizontalMovement * (PlayerManager.Instance.stats.playerRunSpeed / 2f), PlayerManager.Instance.playerRigidBody.velocity.y);
            PlayerManager.Instance.playerRigidBody.velocity = Vector3.SmoothDamp(PlayerManager.Instance.playerRigidBody.velocity, targetVelocity, ref currentVelocity, smoothAirControll);
        }
    }