I want to make enemy follow player, I want the enemy follow the player but only the axis on 2D platfromer

I tried this code but the problem is Enemy starts floating on the Y axis.
here the code:-

public float moveSpeed;
private Transform target;
    	// Use this for initialization
    	void Start () 
            target = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
    	// Update is called once per frame
    	void Update () 
            transform.position = Vector2.MoveTowards(transform.position, target.position, moveSpeed * Time.deltaTime);

ScreenShots of my game:-

Good day.

this is because target.position.y is little higher (not the same) as transfomr.position.y
You have 2 options, change the center og the image to mkae it touch the ground at that y coord, or just don’t change the Y.

Best way is to use move towards target but only changing the X value.

Do this:

transform.position = Vector2.MoveTowards(transform.position, new Vector2 (target.position.x, transform.position.y), moveSpeed * Time.deltaTime);

AS you can see, it will move now to a position with X coord = target X coord, but Y coord will be the same during time.