質問編集履歴

2

コルーチンが行われているスクリプトを追加しました

2018/06/17 15:24

投稿

yuukuriuttto
yuukuriuttto

スコア24

test CHANGED
File without changes
test CHANGED
@@ -90,19 +90,195 @@
90
90
 
91
91
  ```
92
92
 
93
-
93
+ ### スタートコルーチンが書かれているscript
94
+
95
+
96
+
97
+ ```ここに言語名を入力
98
+
99
+ using UnityEngine;
100
+
101
+ using System.Collections;
102
+
103
+ using UnityEngine.UI;
104
+
105
+
106
+
107
+ public class ActionButton : MonoBehaviour
108
+
109
+ {
110
+
111
+ public float _mb;
112
+
113
+ public GameObject NotFixed;
114
+
115
+ public GameObject DestroyButton;
116
+
117
+ public GameObject GatheringButton;
118
+
119
+ public GameObject StopProcessingButton;
120
+
121
+ public GameObject Coniferous;
122
+
123
+ public GameObject Branches;
124
+
125
+ public float intarvar = 10.0f;
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+ Slider _slider;
134
+
135
+
136
+
137
+ //中断するかどうかのフラグ
138
+
139
+ public bool Interruption;
140
+
141
+
142
+
143
+ //2倍減少中かのフラグ
144
+
145
+ private bool boost = false;
146
+
147
+
148
+
149
+ //標準の減少量
150
+
151
+ private float decreaseSpeed = 0.1f;
152
+
153
+
154
+
155
+ void Start()
156
+
157
+ {
158
+
159
+ // スライダーを取得する
160
+
161
+ _slider = GameObject.Find("CalorieSlider").GetComponent<Slider>();
162
+
163
+
164
+
165
+ StopProcessingButton.SetActive(false);
166
+
167
+
168
+
169
+ }
170
+
171
+
172
+
173
+ void Update()
174
+
175
+ {
176
+
177
+ if(boost)
178
+
179
+ {
180
+
181
+ _slider.value -= Time.deltaTime * decreaseSpeed * 10000.0f;
182
+
183
+ }
184
+
185
+
186
+
187
+ else
188
+
189
+ {
190
+
191
+ _slider.value -= Time.deltaTime * decreaseSpeed;
192
+
193
+ }
194
+
195
+ }
196
+
197
+
198
+
199
+ public void OnClick()
200
+
201
+ {
202
+
203
+ //Coniferous = GameObject.Find("Coniferous");
204
+
205
+ //Renderer ConiferousRenderer = Coniferous.GetComponent<Renderer>();
206
+
207
+ //Destroy(Coniferous);
208
+
209
+ StartCoroutine("ExecutionTime");
210
+
211
+ //ConiferousRenderer.enabled = false;
212
+
213
+ //Instantiate(Branches, transform.position, Quaternion.identity);
214
+
215
+ //DestroyButton.SetActive(false);
216
+
217
+ //GatheringButton.SetActive(false);
218
+
219
+
220
+
221
+ }
222
+
223
+
224
+
225
+ IEnumerator ExecutionTime()
226
+
227
+ {
228
+
229
+
230
+
231
+
232
+
233
+ DestroyButton.SetActive(false);
234
+
235
+ GatheringButton.SetActive(false);
236
+
237
+
238
+
239
+ StopProcessingButton.SetActive(true);
240
+
241
+
242
+
243
+ boost = true;
244
+
245
+
246
+
247
+ yield return new WaitForSeconds(5.0f);
248
+
249
+
250
+
251
+ boost = false;
252
+
253
+
254
+
255
+
256
+
257
+ StopProcessingButton.SetActive(false);
258
+
259
+ //Debug.Log("ok");
260
+
261
+
262
+
263
+ //GameObject.Find("DestroyButton").GetComponent<Image>().enabled = false;
264
+
265
+ gameObject.SetActive(false);
266
+
267
+ }
268
+
269
+
270
+
271
+ }
272
+
273
+ ```
94
274
 
95
275
  ### 試したこと
96
276
 
97
277
 
98
278
 
279
+
280
+
99
- コールチを行っているscriptを付けているオブジェクトを、コルーチンを止めたいscriptの方取得して
281
+ ボタが押されたときにActionButtonスリプコルーチンをStopCoroutine()止まるはずが止まらず
100
-
101
-
102
-
103
- 中断フラグが立っていたら止めるみたいな処理を書いてみましたが動かず
104
-
105
-
106
282
 
107
283
  ### 補足情報(FW/ツールのバージョンなど)
108
284
 

1

scriptにStopCoroutinを追加した処理を追記しました

2018/06/17 15:24

投稿

yuukuriuttto
yuukuriuttto

スコア24

test CHANGED
File without changes
test CHANGED
@@ -42,23 +42,33 @@
42
42
 
43
43
  GameObject Coniferous;
44
44
 
45
-
45
+ GameObject ActionButton;
46
+
47
+
46
48
 
47
49
  // Use this for initialization
48
50
 
49
- void Start () {
51
+ void Start()
52
+
53
+ {
50
54
 
51
55
  Coniferous = GameObject.Find("Coniferous");
52
56
 
53
- }
57
+ ActionButton = GameObject.Find("ActionButton");
54
58
 
55
-
59
+ }
56
60
 
57
- // Update is called once per frame
58
61
 
59
- void Update () {
60
62
 
61
- ActionButton di = GetComponent<ActionButton>();
63
+ // Update is called once per frame
64
+
65
+ void Update()
66
+
67
+ {
68
+
69
+
70
+
71
+
62
72
 
63
73
  }
64
74
 
@@ -68,17 +78,11 @@
68
78
 
69
79
  {
70
80
 
81
+ ActionButton di = GetComponent<ActionButton>();
82
+
71
83
 
72
84
 
73
- //if(Interruption)
85
+ StopCoroutine("ExecutionTime");
74
-
75
- //{
76
-
77
- // yield break;
78
-
79
- //}
80
-
81
-
82
86
 
83
87
  }
84
88