Roatate 2D object based on only the x axiz of mouse position

Hello, i have this coed that rotates an object based on mouse position

void LookAtMouse()
    {
        var dir = Input.mousePosition - Camera.main.WorldToScreenPoint(transform.position);
        var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
         transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
    }

But i need my object’s rotation to be affected only by the x position of the mouse.
Can someone please help me with this one?

Hi, try this.

var mousePosXOnly = new Vector2(Input.mousePosition.x, 0f);

var dir = mousePosXOnly - Camera.main.WorldToScreenPoint(transform.position);

var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;

transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);