Finding relative mouse position

Hi all!

I am having some problems with my mouse relative positions. I am working in the Unity 2D envoirement and I have this transform which moves to the left and right, and I wanted to let the character face the direction of the cursor. But I can’t figure out how

This is what I got now:

if(Input.mousePosition.x > transform.position.x){transform.localScale = Vector3(1,1,1);}
if(Input.mousePosition.x < transform.position.x){transform.localScale = Vector3(-1,1,1);}{transform.localScale = Vector3(-1,1,1);}

This seems to work in some way, but the transform only changes direction when the cursor is all the way to the left of the screen. What I would like to see, is that the transforms direction changes when the cursors position is smaller/larger the transform.

Does anyone know how to fix this?

Thanks in advance!

I would look at

Camera point to world point
and maybe Transform.LookAt()

Get the mouse position in world space (you are getting screen space, which is the main problem) and make your object Transform.LookAt(It) or build your own function to rotate to face that point.

Vector3 pos = Camera.main.ScreenToWorldPoint (Input.mousePosition);