2D arm rotation using mouse

I’m trying to rotate the arm (plane) object in z axis using the x and y positions of the mouse. I did the same thing in c++ language a while a go, but I feel like there might be an easier way in unity.

I tried this code in my arm object, but it rotates in x and y axis. opposite of what I want.

var position = Input.mousePosition;
newposition = Vector3(position.x,position.y,-camera.main.transform.position.z);
var lastposition = camera.main.ScreenToWorldPoint(newposition);
transform.LookAt(lastposition);

Has anyone did something similar?

Thanks

If you want to rotate around the Z axis, then you can use transform.LookAt, but you need to use it a bit differently. This function can take a second parameter to control the upward direction of the object. If you keep the point that the object is looking at the same but change the upward direction, you will have the object rotating around the Z axis.