Skip to content

Commit a814932

Browse files
author
Hinen
committed
StopTouchableTimer
1 parent 2231b01 commit a814932

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

Assets/MultiTouchControlButton.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,52 @@
55

66
public class MultiTouchControlButton : Button {
77
private static bool _touchable = true;
8-
8+
99
public bool multiTouchable = true;
1010

11+
private Coroutine _touchableTimerCoroutine;
12+
13+
private void OnDestroy() {
14+
StopTouchableTimer();
15+
}
16+
1117
public override void OnPointerClick(PointerEventData eventData) {
1218
if (!IsTouchable())
1319
return;
14-
20+
1521
base.OnPointerClick(eventData);
1622
}
1723

1824
public override void OnSubmit(BaseEventData eventData) {
1925
if (!IsTouchable())
2026
return;
21-
27+
2228
base.OnSubmit(eventData);
2329
}
2430

2531
private bool IsTouchable() {
2632
if (!multiTouchable && !_touchable)
2733
return false;
2834

29-
StartCoroutine(StartTouchableTimer());
35+
_touchableTimerCoroutine = StartCoroutine(StartTouchableTimer());
3036
return true;
3137
}
3238

3339
private IEnumerator StartTouchableTimer() {
3440
_touchable = false;
35-
41+
3642
yield return new WaitForSeconds(0.1f);
37-
43+
44+
StopTouchableTimer();
45+
}
46+
47+
private void StopTouchableTimer() {
48+
if (_touchableTimerCoroutine == null)
49+
return;
50+
51+
StopCoroutine(_touchableTimerCoroutine);
52+
3853
_touchable = true;
54+
_touchableTimerCoroutine = null;
3955
}
4056
}

0 commit comments

Comments
 (0)