回答編集履歴
2
閉じるカッコが不足していたので修正
answer
CHANGED
@@ -27,5 +27,6 @@
|
|
27
27
|
if (di != null) {
|
28
28
|
di.Stop();// ActionButtonクラスで動いてるコルーチンをActionButtonのStopを呼び出す事で停止.
|
29
29
|
}
|
30
|
+
}
|
30
31
|
}
|
31
32
|
```
|
1
具体的サンプル追記
answer
CHANGED
@@ -1,1 +1,31 @@
|
|
1
|
-
StopCoroutine() では駄目ですか?
|
1
|
+
StopCoroutine() では駄目ですか?
|
2
|
+
|
3
|
+
(コメントを受けて追記)
|
4
|
+
外部からというのは例えばこういうイメージです(直接関係ない部分は色々記載省略してます)
|
5
|
+
|
6
|
+
```c#
|
7
|
+
// コルーチンの動いてるクラス.
|
8
|
+
public class ActionButton : MonoBehaviour {
|
9
|
+
private IEnumerator coroutine;
|
10
|
+
void Start() {
|
11
|
+
coroutine = ExecutionTime()
|
12
|
+
}
|
13
|
+
public void OnClick() {
|
14
|
+
StartCoroutine(coroutine);// コルーチンは自クラスで開始したい.
|
15
|
+
}
|
16
|
+
public void Stop() {// コルーチンの停止を外から呼び出したい.
|
17
|
+
StopCoroutine(coroutine);// コルーチン停止.
|
18
|
+
}
|
19
|
+
IEnumerator ExecutionTime() {// コルーチン.
|
20
|
+
(略)
|
21
|
+
}
|
22
|
+
}
|
23
|
+
// 自分以外のクラスで動いてるコルーチンをこのクラスから停止したい.
|
24
|
+
public class InterruptionButtonScr : MonoBehaviour {
|
25
|
+
public void OnClick() {
|
26
|
+
ActionButton di = GetComponent<ActionButton>();
|
27
|
+
if (di != null) {
|
28
|
+
di.Stop();// ActionButtonクラスで動いてるコルーチンをActionButtonのStopを呼び出す事で停止.
|
29
|
+
}
|
30
|
+
}
|
31
|
+
```
|