Rotate 2D Object on Z axis to Always be Facing Mouse y position

The object I’m trying to rotate is also following the mouse movement along the y axis. It does rotate along the z axis, but only when it reaches the edge of the screen. I’m wanting the object to always be facing the mouse so that it appears to be looking at it.

Here is the code I’m using

    Vector3 objPos= new Vector3 (2.5f, this.transform.position.x, 0 * moveSpeed);
	float mousePos = Input.mousePosition.y / Screen.height * 12f;
	ninjaPos.y = Mathf.Clamp (mousePos, 1.25f, 10.75f);
	this.transform.position  = objPos;

	Vector3 pos = Camera.main.WorldToScreenPoint(transform.position);
	Vector3 dir = Input.mousePosition - pos;
	float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
	transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

A simple way to do this is to use the LookAt method of transform :

public Transform target;

void Update()
{
    transform.LookAt(target);
}

The target should be the world point of the mouse position :

target.position = Camera.main.ScreenToWorld(Input.mousePosition);