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.clickTime Example Please

Discussion in 'Scripting' started by MadeThisName, Aug 19, 2015.

  1. MadeThisName

    MadeThisName

    Joined:
    Mar 14, 2015
    Posts:
    115
    Trying to figure out how to use PointerEventData.clicktime for use with limiting the second click time of double clicking. Here is what i have so far

    Code (CSharp):
    1.  
    2.     public void OnPointerEnter (PointerEventData data)
    3.     {
    4.         if (data.clickCount == 2) {
    5.         }
    6.     }
    Not much i know but i couldnt for the life of me find any examples for PointerEventData.clicktime.
    Thanks guys
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Code (CSharp):
    1.  
    2.     public void OnPointerEnter (PointerEventData data)
    3.     {
    4.         if (data.clickTime < 0.1f) {
    5.             Debug.Log("A double click")
    6.         }
    7.     }
     
    MadeThisName likes this.
  3. MadeThisName

    MadeThisName

    Joined:
    Mar 14, 2015
    Posts:
    115
    Faceplam.....That easy. Why do i always complicate things lol. Thank you Kindly.
     
  4. MagyarPeter

    MagyarPeter

    Joined:
    Nov 28, 2020
    Posts:
    10
    For me, the clickTime returns the time when the event was created, with 3 seconds delay compared to the Time.time.
    So if I ~instantly press and release the mouse button, then my code prints -3 seconds.
    My code:
    public class MenuButton : MonoBehaviour, IPointerClickHandler
    {
    private PointerEventData e;
    public void OnPointerClick(PointerEventData eventData)
    {
    e = eventData;
    }
    void Update()
    {
    if (e != null)
    {
    if (!e.eligibleForClick)
    {
    print("clicked" + (Time.time - e.clickTime).ToString());
    e = null;
    }
    }
    }
    }
     
  5. MagyarPeter

    MagyarPeter

    Joined:
    Nov 28, 2020
    Posts:
    10
    FIXED: I have to use unscaled time instead of normal time
    public class MenuButton : MonoBehaviour, IPointerClickHandler
    {
    private PointerEventData e;
    public void OnPointerClick(PointerEventData eventData)
    {
    e = eventData;
    }
    void Update()
    {
    if (e != null)
    {
    if (!e.eligibleForClick)
    {
    print("clicked" + (Time.unscaledTime - e.clickTime).ToString());
    e = null;
    }
    }
    }
    }