Does anyone know why the y isn't working?

The x works and it makes the player walk horizontal but the y just moves it horizontal too.
Can someone help me?

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

public class PlayerMovement : MonoBehaviour
{
    public float speed;

    private float x;
    private float y;

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        x = Input.GetAxis("Horizontal");
        y = Input.GetAxisRaw("Vertical");
        transform.position += (Vector3)new Vector2(x * speed * Time.deltaTime, 0);
        transform.position += (Vector3)new Vector2(y * speed * Time.deltaTime, 0);
    }
}

transform.position is a Vector3
so you’re adding the right hand part to it via +=

adding two vectors results in
new Vector3(left.x + right.x, left.y + right.y, left.z + right.z);

on your right hand expression you have a 2D Vector2 that has only xy
you evaluate only x, and make a Vector2 that’s (x, 0)

then you cast that to Vector3 and get Vector3(x, 0, 0)
when you add that to left hand side, everything’s fine

but then in the next line you make a Vector2 that’s (y, 0)
then you cast that to Vector3 and get Vector3(y, 0, 0)
when you add that to left hand side, remember

new Vector3(left.x + right.x, left.y + right.y, left.z + right.z);

your right.x is suddenly a value for y

just change your last line into

transform.position += (Vector3)new Vector2(0, y * speed * Time.deltaTime);

I’d also advise you not to cast vectors like that because it will lead you into problems that are hard to debug
make a utility function instead, so that you can see it, and know what it does exactly

i.e.

static private Vector3 to_vec3xy(Vector2 vec2) => new Vector3(vec2.x, vec2.y, 0f);

though this seems unnecessary, trust me, you’ll soon enough end up having to do

static private Vector3 to_vec3xz(Vector2 vec2) => new Vector3(vec2.x, 0f, vec2.y);

and this tends to be confusing, just don’t cross-cast between them
also because downcasting is unsafe in Unity

i.e.

var vec = (Vector2)new Vector3(15f, 0f, 17f); // silently ends up being (15f, 0f)

you can also bundle this together, for clarity

transform.position += to_vec3xy(new Vector2(x, y) * speed * Time.deltaTime);

it’s the same thing and much more readable than this

transform.position += (Vector3)new Vector2(x * speed * Time.deltaTime, 0);
transform.position += (Vector3)new Vector2(0, y * speed * Time.deltaTime);

right?

it also has fewer operations, making it negligibly faster

I think the 2nd line should be :

 transform.position += (Vector3)new Vector2( 0, y * speed * Time.deltaTime);