Unity Raycast Problems

Probably an easy fix, but for a beginner like me I’ve been going crazy.

RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, transform.right, distance);

        if(hitInfo.collider != null && hitInfo.collider.CompareTag("Player"))
        {
            Debug.Log("Player Sighting");

        } else {
            Debug.Log("Cannot Find Player");

        }

The raycast is pointing where the enemy gun is pointing

Right now “Cannot Find Player” is always showing up in the console, even if the Player is right where the raycast should be. I also tested that hitInfo.collider != null is never working.

Hi there, I’m also a beginner but I think I might have a few ideas of what you should try. Is this game in 2D or 3D?
@Corrimba