My Eventsystem problem

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.EventSystems;

public class raycasttestscript : MonoBehaviour, IPointerDownHandler
{
    public void OnPointerDown(PointerEventData eventData)
    {
        Debug.Log("the gameobject" + this.gameObject.name + "have been hit");
    }
}

I have a code like above, attach to an ui gameobject, having eventsystem running and raycast attaching to both the camera and the canvas ui gameobject, what do i missing?

If the script is on the Camera or Canvas, then it may not be working because neither of these is a UI element. Try adding it to a GameObject that has a UI Image, Button, or Text component.

I believe it has to have a “raycast target” property, which has to be enabled:
image

If that property doesn’t exist or is disabled, that element will not receive input (or does not support it).

Can be simplified to this:
Debug.Log("the gameobject" + name + "have been hit");

The this identifier is almost never needed in C#, only in cases where there is a naming ambiguity between current and base class’ method or property.

I got raycast target tick but it still didn’t work.