FPS - Attach a gun to hands and move arms when aiming up and down

I’m kinda new to Unity, and I’m trying to adapt a Pistol to this Mixamo Character with some Mixamo Animations. I want the pistol to move with the camera ( CSGO aim system ) and also I want the arms to move with the gun. I saw something about IK and various posts but can’t find/apply the solution. Can someone help?

Mixamo Character: The Boss

Mixamo Animations: Pistol Idle ( the one that doesn’t move ), Pistol Run ( The slower one )

Pistol : One of these Modern Guns: Handgun | 3D Guns | Unity Asset Store

So there’s a difference between IK and just general tracking. I think the shoulders will be doing most of the work so I will just focus on that problem. If you really want to mess with IK, there are a lot of posts here that do an effective simple version of that, and you will have to modify the code heavily for your specific Transforms. There is also an Asset called HeadLookController (look it up) which is a gem. That script contains this method which I use all the time:

public static float AngleAroundAxis (Vector3 dirA, Vector3 dirB, Vector3 axis) {
        // Project A and B onto the plane orthogonal target axis
        dirA = dirA - Vector3.Project(dirA, axis);
        dirB = dirB - Vector3.Project(dirB, axis);
        // Find (positive) angle between A and B
        float angle = Vector3.Angle(dirA, dirB);
        // Return angle multiplied with 1 or -1
        return angle * (Vector3.Dot(axis, Vector3.Cross(dirA, dirB)) < 0 ? -1 : 1);

Just for rotating the arms up and down, assuming the X axis is the one pointing out and also assuming that the Y axis is the bone’s pointing vector, you would just use it like this:

Vector3 armPivot = arm.right; //may have to multiply by -1
Vector3 armPointing = arm.up;
Vector3 toDir = Camera.main.transform.forward;
//Now we do from armPointing to toDir
float amtToUp = AngleAroundAxis(armPointing, toDir, armPivot);
arm.Rotate(amtToUp, armPivot, Space.World);

//Now for the horizontal, assuming pivot is on Z:
armPivot = arm.forward;
armPointing = arm.up;
toDir = Camera.main.transform.forward;
float amtToSide = AngleAroundAxis(armPointing, toDir, armPivot);
arm.Rotate(amtToSide, armPivot, Space.World);

As for IK, it’s more or less the same thing with smartly placed limits on different segments in the chain. Like for example, the arm would only go 0.5 that amount where as the forearm would then go the full amount afterwards. The trouble becomes fixing backward bending elbows, so you should probably stick to just shoulders for now.

Edit: I forgot to mention that you would call these changes in LateUpdate(); Alternatively if the player rotates horizontally and you want to ignore everything I’ve mentioned, you might play around with using Animation Layers and having a second layer with an arm mask that constantly plays an upwards facing motion and you would programmatically adjust the layer weight to reflect how high the arms go.