Hand and gun rotation problem, Third Person Shooter

Hello, I’m facing a problem with Unity. I’m working on a TPS game.
My problem is that I want to make my character’s hand always keep the same rotation (perpendicular to the ground), but the problem is when I play animations sometimes my character’s hand rotate and the gun’s rotation (gun is attached to hand bone) is not perpendicular anymore. (Sorry my english is very bad, but you can look at the images, may be you will better understand)

Thanks for your help

Vector3 rot = Quaternion.Euler(transform.eulerAngles);
transform.rotation = Quaternion.Euler(rot.x,rot.y,0);