Use Raycast on canvas child gameobject

I’m using this joystick and Mirror for networking

What I wanted is to detect the gameobject Joystick which is the child of Canvass using Raycast

I’ve tried this script

public class ShootBullet : NetworkBehaviour
{
[SerializeField]
private GameObject bulletPrefab;
private GameObject bullet;

// Set via the Inspector in Units/second
[SerializeField] private float _moveSpeed = 2f;
[SerializeField] private Camera _camera;
Vector3 touch_Pos = new Vector3(0, 0, 0);

private void Awake()
{
    if (!_camera) _camera = Camera.main;
}

void Update()
{
    if (Input.touchCount > 0 && this.isLocalPlayer)
    {
        Ray ray = _camera.ScreenPointToRay(Input.GetTouch(0).position);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            if (hit.collider != null)
            {
                Debug.Log(hit.collider.gameObject.name);
            }
        }
    }
    
}

}

But it doesn’t work

You need to use the GraphicRaycaster for UI elements. You fetch a reference to the GraphicRaycaster, get your current PointerEventData (or create your own instance of it and feed it your current mouse position), depending on where you raycast from and pass it a List of RaycastResults which will get the results appended. The code-example in the doc I linked gives you a perfetcly simple and valid example.