Raycast does not work?

so this code doesn’t do ray casts
please help
it detects nothing

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

public class Movement1 : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {

    }
    // Update is called once per frame
    void Update()
    {
        Camera.main.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y,-10);
        if (Input.GetKey(KeyCode.RightArrow))
        {
            //weapon stuff here
            if (GetComponent<Rigidbody2D>())
            {
                GetComponent<Rigidbody2D>().velocity = GetComponent<Rigidbody2D>().velocity + new Vector2(0.3f, 0);
                gameObject.transform.localScale = new Vector2(0.4f, 0.4f);
            }
        }
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            if (GetComponent<Rigidbody2D>())
            {
                GetComponent<Rigidbody2D>().velocity = GetComponent<Rigidbody2D>().velocity + new Vector2(-0.3f, 0);
                gameObject.transform.localScale = new Vector2(-0.4f, 0.4f);
            }
        }
        if (Input.GetKeyDown(KeyCode.Z))
        {
            //weapon stuff here
            if (GetComponent<Rigidbody2D>())
            {
                LayerMask mask = LayerMask.NameToLayer("Player");
                RaycastHit2D hitd = Physics2D.Raycast(transform.position, -Vector2.up,1,mask);
                Debug.Log(mask);
                if (hitd.collider == null)
                {
                    Debug.Log("Cant find floor");
                }
                else
                {
                    Debug.Log(hitd.collider.name);
                    // Raycast(gameObject.transform.position, new Vector2(0,-1), null, null, 5);

                    GetComponent<Rigidbody2D>().velocity = GetComponent<Rigidbody2D>().velocity + new Vector2(0, 10);
                }
            }
        }
    }
}

The code is running fine, although not really optimized. I tried the script in a 3D world, with 3D objects and a 2D rigidbody. I couldn’t get the raycast to work. While the regular raycast works fine. So my guess is, is that you are mixing 2D and 3D together.