Fix double click on explode button

This commit is contained in:
FlorianSpeicher
2025-07-08 15:21:54 +02:00
parent 372ec517e8
commit 89b09c8ce5
2 changed files with 13 additions and 13 deletions

View File

@@ -27386,7 +27386,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1591058970} m_GameObject: {fileID: 1591058970}
m_Enabled: 1 m_Enabled: 0
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 01614664b831546d2ae94a42149d80ac, type: 3} m_Script: {fileID: 11500000, guid: 01614664b831546d2ae94a42149d80ac, type: 3}
m_Name: m_Name:
@@ -27447,7 +27447,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1591058970} m_GameObject: {fileID: 1591058970}
m_Enabled: 0 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2518c50cb3fc6a6458d4b743c2f69c7d, type: 3} m_Script: {fileID: 11500000, guid: 2518c50cb3fc6a6458d4b743c2f69c7d, type: 3}
m_Name: m_Name:

View File

@@ -3,10 +3,11 @@ using System.Collections.Generic;
using TMPro; using TMPro;
using Unity.VisualScripting; using Unity.VisualScripting;
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Serialization; using UnityEngine.Serialization;
using UnityEngine.UI; using UnityEngine.UI;
public class ExplodeModel : MonoBehaviour, IResettable public class ExplodeModel : MonoBehaviour, IResettable, IPointerDownHandler
{ {
public ModelManager mm; public ModelManager mm;
public GameObject baseModel; public GameObject baseModel;
@@ -15,16 +16,21 @@ public class ExplodeModel : MonoBehaviour, IResettable
List<Vector3> goalPos = new List<Vector3>(); List<Vector3> goalPos = new List<Vector3>();
List<Vector3> initialPos = new List<Vector3>(); List<Vector3> initialPos = new List<Vector3>();
private bool pressed = false;
static readonly int finalTick = 60 * 2; // 60fps * 2sek static readonly int finalTick = 60 * 2; // 60fps * 2sek
bool explode = false; bool explode = false;
int tick = finalTick + 1; int tick = finalTick + 1;
float lastClickTime = -1f;
const float debounceTime = 0.3f; // 300ms Sperre
void Start() public void OnPointerDown(PointerEventData eventData)
{ {
GetComponent<Button>().onClick.AddListener(Explode); if (Time.time - lastClickTime < debounceTime)
} return; // Ignoriere doppeltes Event
lastClickTime = Time.time;
Explode();
}
void Update() void Update()
{ {
@@ -50,11 +56,6 @@ public class ExplodeModel : MonoBehaviour, IResettable
void Explode() void Explode()
{ {
pressed = !pressed;
if (!pressed)
{
return;
}
if (!explode) // before switching to true if (!explode) // before switching to true
{ {
initialPos.Clear(); initialPos.Clear();
@@ -88,7 +89,6 @@ public class ExplodeModel : MonoBehaviour, IResettable
tf.transform.localPosition = initialPos[i]; //reset all tf.transform.localPosition = initialPos[i]; //reset all
} }
} }
pressed = false;
explode = false; explode = false;
text.text = "Explode"; text.text = "Explode";
tick = finalTick + 1; tick = finalTick + 1;