How to add weapon sway?(c#)

Ya… Thanks(c#)

Here, this one handles rotation left/right

using UnityEngine;
using System.Collections;

public class WDragRotation : MonoBehaviour {
    float amount = 0.02f;
    float maxamount = 0.03f;
    float smooth = 3;
    private Quaternion def;
    private bool  Paused = false;

    void  Start (){
        def = transform.localRotation;
    }

    void  Update (){
        float factorX = (Input.GetAxis("Mouse Y")) * amount;
        float factorY = -(Input.GetAxis("Mouse X")) * amount;
        //float factorZ = -Input.GetAxis("Vertical") * amount;
        float factorZ = 0 * amount;
        
        if(!Paused){
        if (factorX > maxamount)
        factorX = maxamount;
 
        if (factorX < -maxamount)
        factorX = -maxamount;
 
        if (factorY > maxamount)
        factorY = maxamount;
 
        if (factorY < -maxamount)
        factorY = -maxamount;
 
        if (factorZ > maxamount)
        factorZ = maxamount;
 
        if (factorZ < -maxamount)
        factorZ = -maxamount;
 
        Quaternion Final = Quaternion.Euler(def.x+factorX, def.y+factorY, def.z+factorZ);
        transform.localRotation = Quaternion.Slerp(transform.localRotation, Final, (Time.time * smooth));
        }
    }
}

This one allows weapons to rotate on the X axis.

sing UnityEngine;
using System.Collections;

public class WDragMove : MonoBehaviour {
    public float amount = 0.02f;
    public float maxamount = 0.03f;
    public float smooth = 3;
    private Quaternion def;
 
    void  Start (){
        def = transform.localRotation;
    }
 
    void  Update (){
 
        float factorZ = -(Input.GetAxis("Horizontal")) * amount;
        //float factorY = -(Input.GetAxis("Jump")) * amount;
        //float factorZ = -Input.GetAxis("Vertical") * amount;
        
        //if (factorX > maxamount)
        //factorX = maxamount;
 
        //if (factorX < -maxamount)
        //factorX = -maxamount;
 
        //if (factorY > maxamount)
        //factorY = maxamount;
 
        //if (factorY < -maxamount)
        //factorY = -maxamount;
 
        if (factorZ > maxamount)
        factorZ = maxamount;
 
        if (factorZ < -maxamount)
        factorZ = -maxamount;
 
        Quaternion Final= Quaternion.Euler(0, 0, def.z+factorZ);
        transform.localRotation = Quaternion.Lerp(transform.localRotation, Final, (Time.deltaTime * amount) * smooth);  
    } 
}