How to make this work only when the mouse button is clicked

So i made a script that allows you to rotate your camera but i just want it to work while the first mouse button is down and i want the mouse to stay in one place, here is my code:

 private const float Y_ANGLE_MIN = 0f;
    private const float Y_ANGLE_MAX = 50f;

    public Transform lookAt;
    public Transform camTransform;

    private Camera cam;

    private float distance = 10f;
    private float currentX = 0f;
    private float currentY = 0f;
    private float sensivityX = 4f;
    private float sensivityY = 1f;

    private void Start()
    {
        camTransform = transform;
        cam = Camera.main;
    }

    private void Update() {
        currentX += Input.GetAxis("Mouse X");
        currentY += Input.GetAxis("Mouse Y");
        currentY = Mathf.Clamp(currentY, Y_ANGLE_MIN, Y_ANGLE_MAX);
    }

    private void LateUpdate() {
        Vector3 dir = new Vector3(0, 0, -distance);
        Quaternion rotation = Quaternion.Euler(currentY,currentX,0);
        camTransform.position = lookAt.position + rotation * dir;
        camTransform.LookAt(lookAt.position);
    }

If you want it to happen, when the Mouse Button is pressed, the following should work:

     private void Update() {
         if(Input.GetMouseButton(0))
         {
               currentX += Input.GetAxis("Mouse X");
               currentY += Input.GetAxis("Mouse Y");
               currentY = Mathf.Clamp(currentY, Y_ANGLE_MIN, Y_ANGLE_MAX);
         }
     }

What do you mean with “want the mouse to stay in one place”? That the mouse cursor is always in the middle of the screen? That should be possible with Cursor.lockState ( Unity - Scripting API: Cursor.lockState ), but i didn’t tested it.