How to move in multiple directions at same time?

So im trying to make a 3d character move only on the X,Y axis, but I can only make it move vertically and horizontally, and not diagonally.

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

public class Movement : MonoBehaviour
{
    public GameObject player;
    public float speed;
    private Vector3 pos;


    // Start is called before the first frame update
    void Start()
    {
        
        pos = player.transform.position;
        
    }

    // Update is called once per frame
    void Update()
    {
        Vector3 current = player.transform.position;

        
        player.transform.position = Vector3.Lerp(current, pos, 10 * Time.deltaTime);
        

        float y = player.transform.position.y;
        float x = player.transform.position.x;
        float z = player.transform.position.z;

        // I suspect the problem is here. Are the lines of code setting 'pos' interfering with each other?
         if (Input.GetKey(KeyCode.W))
        {
            pos = new Vector3(x, y + speed, z);           
        }
        else if (Input.GetKey(KeyCode.A))
        {         
            pos = new Vector3(x - speed, y, z);
        }
        else if (Input.GetKey(KeyCode.S))
        {           
            pos = new Vector3(x, y - speed, z);
        }
        else if (Input.GetKey(KeyCode.D))
        {           
            pos = new Vector3(x + speed, y, z);
        }
        
    }
}

Yes, the issue is related to those if/else if blocks. The solution is similar to what KevRev said, but it’s not as simple as removing the “elses”. If you do just that you’ll have the same problem since the last if that’s evaluated to true will override any pos set by previous keys.

You have to use some kind of acumulator for the input, update the acumulator on every keycode and then alter the position based on that. Something like this:

     Vector3 input = Vector3.zero;
     if (Input.GetKey(KeyCode.W))
     {
         input.y += speed;
     }
     if (Input.GetKey(KeyCode.S))
     {           
         input.y -= speed;
     }
     if (Input.GetKey(KeyCode.A))
     {         
         input.x -= speed;
     }
     if (Input.GetKey(KeyCode.D))
     {           
         input.x += speed;
     }

    pos += input;

Also note that Unity already provides something similar to this. You can set up an “axis” on the Input settings for A and D, and for W and S (actually, I think they’re already created by default), and then do something like:

    Vector3 input = new Vector3(Input.GetAxis("Horizontal"),Input.GetAxis("Vertical"),0);
    pos += input * speed;

It’s not exactly the same as checking each key (an axis simulates acceleration and deadzones like a joystick), but it keeps the code a lot cleaner.