Y position locked

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float moveSpeed;

    private bool isMoving;

    private Vector2 input;

    private void Update()
    {
        if (!isMoving)
        {
            input.x = Input.GetAxisRaw("Horizontal");
            input.y = Input.GetAxisRaw("Vertical");

            if (input.x != 0) input.y = 0;
           
            if (input != Vector2.zero)
            {

                var targetPos = transform.position;
                targetPos.x += input.x;
                targetPos.y =+ input.y;

                StartCoroutine(Move(targetPos));
            }

        }
    }

    IEnumerator Move(Vector3 targetPos)
    {
        isMoving = true;

        while ((targetPos - transform.position).sqrMagnitude > Mathf.Epsilon)
        {
            transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
            yield return null;
        }
        transform.position = targetPos;

        isMoving = false;
    }



}

I can move to y 1 max and y -1 max but when x is changed y goes back to 0

the y-axis input gets reset to 0 whenever there is horizontal input.

You should remove the line ‘ if (input.x != 0) input.y = 0;’ to enable the player to move freely in both horizontal and vertical directions.