How to rotate an object using mouse drag?

I have an object (a gun barrel). I want to rotate it according to the position of the mouse. For example, if I click and drag the mouse to the right. the gun barrel will be rotated diagonally on the right and same as when it’s on the left. is there any available scripts?

Take a look at the Input.mousePosition example. Use the mouse position to alter the rotation of your barrel.