Trouble with checking Raycast

Working on a prototype level editor, and I’m having trouble detecting if a block is under the mouse pointer to be used for a delete function.

Basically, the ray would check under the mouse’s position in the world for an object it would collide with, and would delete it if it came back true (which is being replaced with a Debug.Log), but I can’t seem to get the ray to hit anything or detect anything to hit

void Update() {

Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10f);
Vector3 worldPos = Camera.main.ScreenToWorldPoint(mousePos);
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(worldPos);

if (Input.GetMouseButtonDown(0))
    {
    switch (blockType)
          {
          case (1):
              if (Physics.Raycast(ray, out hit, 20))
              {
                    Debug.Log("Working");
               }
          break;
          }
    }
}

Any help/explanation would greatly be appreciated :slight_smile:

Ray ray = Camera.main.ScreenPointToRay(worldPos);

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);