Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

PointerEventData pointer is being pressed?

Discussion in 'UGUI & TextMesh Pro' started by Rodolfo-Rubens, Mar 7, 2017.

  1. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,196
    I'm trying to find a way to know if the pointer from the pointer event data is being pressed but I'm failing to find a variable in the class to tell if it's pressed or not!
    "clickCount" doesn't resets to 0 if there is no click count and even if it did it's not what I want, I want the exactly current state of the pointer, if it is pressed or not!

    Also, there is not a single documentation on "eligibleForClick".
     
    Last edited: Mar 7, 2017
  2. khemistry

    khemistry

    Joined:
    Jun 16, 2016
    Posts:
    18
    Rodolfo-Rubens likes this.
  3. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,196
    I was doing GetMouseDown, yes, it works, but since it's going to be for touch screen devices I'm afraid something goes wrong.

    It seems like eligibleForClick is what I want, and there is no documentation about it, but it seems to return true when the pointer is being pressed and false otherwise.

    But I just found that OnPointerUp won't be called if I begin my click on nothing (no objects to intersect the event, just the plain canvas).
     
  4. MagyarPeter

    MagyarPeter

    Joined:
    Nov 28, 2020
    Posts:
    10
    public class ExampleClass: MonoBehaviour, IPointerDownHandler, IPointerUpHandler
    {
    bool isDown;

    public void OnPointerDown(PointerEventData eventData)
    {
    isDown = true; //this void is called when the pointed started baing pressed at this UI image, and the raycast is enabled in the Image Component
    }

    public void OnPointerUp(PointerEventData eventData)
    {
    isDown = false; //this void is called even if the pointed stopped being pressed somewhere else
    }
    void Update()
    {
    print(isDown);
    }
    }