-2
\$\begingroup\$

Have a class, which I am calling from PointerClick(in EventTrigger).
Need to recall PointerClick after the first PointerClick((0.2f) seconds later).

\$\endgroup\$
1
  • \$\begingroup\$ It's not immediately clear what you're looking for here - can you explain in more detail? \$\endgroup\$ Commented Feb 27, 2018 at 20:26

2 Answers 2

0
\$\begingroup\$
  1. Make sure you have a PhysicsRaycaster or Phyics2DRaycaster on your camera if the object holding this script is a 3D / 2D object. If it's a UI object, you have to put a GraphicRaycaster
  2. Make sure the object holding this script has a Collider or Collider2D or an Image/RawImage component with RaycastTarget checked
  3. Make sure you have an EventSystem in your scene

using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;

public class ClassName: MonoBehaviour, IPointerClickHandler
{
    public float doubleClickThreshold = 0.2f ;
    public UnityEvent OnDoubleClickDetected;
    private float lastClickTime = -1 ;

    public void OnPointerClick(PointerEventData ped)
    {
         if( Time.time - lastClickTime < doubleClickThreshold )
         {
             if( OnDoubleClickDetected != null )
                 OnDoubleClickDetected.Invoke() ;
         }
         lastClickTime = Time.time ;
    }
}
\$\endgroup\$
4
  • \$\begingroup\$ I want to imitate second click after the first one. \$\endgroup\$ Commented Feb 28, 2018 at 12:06
  • \$\begingroup\$ You want to simulate the double click? I'm afraid this is not possible with Unity only. You have solutions for Windows only if you want. Why do you want the double click? Have you currently something like a listener to a double click event? \$\endgroup\$ Commented Feb 28, 2018 at 12:10
  • \$\begingroup\$ Yes. I have listener. Having problems with cards swipe. What to make all image be raycasted, but then I can't swipe.. \$\endgroup\$ Commented Feb 28, 2018 at 12:12
  • \$\begingroup\$ Please, edit your question and provide all the relevant code if you want an answer fitting your needs. \$\endgroup\$ Commented Feb 28, 2018 at 12:14
0
\$\begingroup\$

Not sure if I understood but you can try: Invoke( method(), time ); to call some method after certain time

documentation: https://docs.unity3d.com/ScriptReference/MonoBehaviour.Invoke.html

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.