回答編集履歴

2

閉じるカッコが不足していたので修正

2018/06/18 03:00

投稿

HiroshiWatanabe
HiroshiWatanabe

スコア2160

test CHANGED
@@ -56,6 +56,8 @@
56
56
 
57
57
  }
58
58
 
59
+ }
60
+
59
61
  }
60
62
 
61
63
  ```

1

具体的サンプル追記

2018/06/18 03:00

投稿

HiroshiWatanabe
HiroshiWatanabe

スコア2160

test CHANGED
@@ -1 +1,61 @@
1
1
  StopCoroutine() では駄目ですか?
2
+
3
+
4
+
5
+ (コメントを受けて追記)
6
+
7
+ 外部からというのは例えばこういうイメージです(直接関係ない部分は色々記載省略してます)
8
+
9
+
10
+
11
+ ```c#
12
+
13
+ // コルーチンの動いてるクラス.
14
+
15
+ public class ActionButton : MonoBehaviour {
16
+
17
+ private IEnumerator coroutine;
18
+
19
+ void Start() {
20
+
21
+ coroutine = ExecutionTime()
22
+
23
+ }
24
+
25
+ public void OnClick() {
26
+
27
+ StartCoroutine(coroutine);// コルーチンは自クラスで開始したい.
28
+
29
+ }
30
+
31
+ public void Stop() {// コルーチンの停止を外から呼び出したい.
32
+
33
+ StopCoroutine(coroutine);// コルーチン停止.
34
+
35
+ }
36
+
37
+ IEnumerator ExecutionTime() {// コルーチン.
38
+
39
+ (略)
40
+
41
+ }
42
+
43
+ }
44
+
45
+ // 自分以外のクラスで動いてるコルーチンをこのクラスから停止したい.
46
+
47
+ public class InterruptionButtonScr : MonoBehaviour {
48
+
49
+ public void OnClick() {
50
+
51
+ ActionButton di = GetComponent<ActionButton>();
52
+
53
+ if (di != null) {
54
+
55
+ di.Stop();// ActionButtonクラスで動いてるコルーチンをActionButtonのStopを呼び出す事で停止.
56
+
57
+ }
58
+
59
+ }
60
+
61
+ ```