Have a class, which I am calling from PointerClick(in EventTrigger).
Need to recall PointerClick after the first PointerClick((0.2f) seconds later).
\$\begingroup\$
\$\endgroup\$
1
-
\$\begingroup\$ It's not immediately clear what you're looking for here - can you explain in more detail? \$\endgroup\$DMGregory– DMGregory ♦2018-02-27 20:26:06 +00:00Commented Feb 27, 2018 at 20:26
Add a comment
|
2 Answers
\$\begingroup\$
\$\endgroup\$
4
- 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
- Make sure the object holding this script has a Collider or Collider2D or an Image/RawImage component with
RaycastTargetchecked - 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 ;
}
}
-
\$\begingroup\$ I want to imitate second click after the first one. \$\endgroup\$GuardFromUA– GuardFromUA2018-02-28 12:06:26 +00:00Commented 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\$Hellium– Hellium2018-02-28 12:10:18 +00:00Commented 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\$GuardFromUA– GuardFromUA2018-02-28 12:12:09 +00:00Commented 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\$Hellium– Hellium2018-02-28 12:14:10 +00:00Commented Feb 28, 2018 at 12:14
\$\begingroup\$
\$\endgroup\$
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