Home>

I want to use pointerPress of PointerEventData class, but I don't know how to use it.

https://docs.unity3d.com/ja/2018.4/ScriptReference/EventSystems.PointerEventData.html
In this manual,
"The GameObject that received OnPointerDown. PointerPress returns the pressed GameObject. It is only valid when the press is released."
Is written.

But actually

  void Update ()
    {
        Debug.Log (new PointerEventData (EventSystem.current) .pointerPress);
    }


I wrote and executed it, but only Null is output to the log.

Doesn't it output the object pressed by the pointer?
Since it was written as OnPointerDown, I thought that PointerDown of EventTrigger was necessary to output, so I attached EventTrigger and then clicked the object with the pointer, but only Null was output as usual. ..

Please tell me how to use pointerPress of PointerEventData to get the object clicked by the pointer.

  • Answer # 1

    Reference site Seeing this site The name of the clicked Object is displayed.
    I do not know from the above information alone, but it can not be used unless IPointerClickHandler is inherited, so please try inheriting this.