Moving object along X axis with mouse

Trying to just move an object along the X axis using the mouse screen position. For some reason the Input.mousePosition doesn’t return a variable so I can’t just use it to do a transform. All the other languages I’ve used I can do this in 2 minutes.

public Transform objectToMove;

	void Start () {
		Cursor.visible = false;
	}

	void Update () {
	 Vector3 mouse = Input.mousePosition;
     Ray castPoint = Camera.main.ScreenPointToRay(mouse);
     RaycastHit hit;
     if (Physics.Raycast(castPoint, out hit, Mathf.Infinity))
     {
         objectToMove.transform.position = hit.point;
     }
	}
}

This moves the object toward the camera and locking the y and z in Rigidbody has no effect

I see no errors… are you sure Camera.main is the camera you want? If i was in your situation i would do:

Debug.log with the moue position

Debug.Log with hit.point

Change camera.main for an assigned GameObject variable (the camera of course) from the scene ( to be sure)

Bye!