Fix double click on ToggleAR

This commit is contained in:
FlorianSpeicher
2025-07-08 15:28:42 +02:00
parent 89b09c8ce5
commit 84dd96544c

View File

@@ -1,14 +1,26 @@
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI; using UnityEngine.UI;
namespace UI namespace UI
{ {
public class ARToggleButton: MonoBehaviour public class ARToggleButton: MonoBehaviour, IPointerDownHandler
{ {
public OVRPassthroughLayer passthroughLayer; public OVRPassthroughLayer passthroughLayer;
private bool pressed = false; //efix variable da button 2 mal pressed wird ?? private bool pressed = false; //efix variable da button 2 mal pressed wird ??
public GameObject raceTrack; public GameObject raceTrack;
float lastClickTime = -1f;
const float debounceTime = 0.3f; // 300ms Sperre
public void OnPointerDown(PointerEventData eventData)
{
if (Time.time - lastClickTime < debounceTime)
return; // Ignoriere doppeltes Event
lastClickTime = Time.time;
TogglePassthrough();
}
void Start() void Start()
{ {
gameObject.GetComponent<Button>().onClick.AddListener(TogglePassthrough); gameObject.GetComponent<Button>().onClick.AddListener(TogglePassthrough);