Combine root motion with Script motion

Hi, Im trying to use both of root mption and script motion. The thing is that I use root motion for combat and moving ground and I want to use script motion in air. But it doesnt work. Here is my code
private void OnAnimatorMove()
{
//_currentState.UpdateAnimatorStates();
if (IsGrounded && !PlayerMovementInput.Player.Jump.WasPressedThisFrame())
{
Vector3 velocity = (_animator.deltaPosition / Time.deltaTime);
velocity.y = _rigidbody2D.velocity.y;
_rigidbody2D.velocity = velocity;
float maxRaycastDistance = .25f;

        Ray ray = new Ray(transform.position + Vector3.up * 0.1f, -transform.up);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, maxRaycastDistance, GroundLayer))
        {
            Vector3 movement = Vector3.ProjectOnPlane(velocity, hit.normal);

            Vector3 surfaceNormal = hit.normal;
            surfaceNormal.z = 0f;
            Quaternion targetRotation = Quaternion.FromToRotation(transform.up, surfaceNormal);
            Quaternion rotationDelta = Quaternion.Euler(0f, 0f, targetRotation.eulerAngles.z);
            transform.rotation = rotationDelta * transform.rotation;
            _rigidbody2D.velocity = movement;
            Debug.DrawRay(ray.origin, ray.direction * maxRaycastDistance, Color.green);
        }
    }
}

The problem is that my character wont jump. It happens because of Raycast part of Code, how to make it work?