-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\$
  • \$\begingroup\$ It's not immediately clear what you're looking for here - can you explain in more detail? \$\endgroup\$ – DMGregory Feb 27 '18 at 20:26
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\$
  • \$\begingroup\$ I want to imitate second click after the first one. \$\endgroup\$ – GuardFromUA Feb 28 '18 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\$ – Hellium Feb 28 '18 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\$ – GuardFromUA Feb 28 '18 at 12:12
  • \$\begingroup\$ Please, edit your question and provide all the relevant code if you want an answer fitting your needs. \$\endgroup\$ – Hellium Feb 28 '18 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\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.