質問編集履歴
2
コルーチンが行われているスクリプトを追加しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -44,13 +44,101 @@
|
|
44
44
|
}
|
45
45
|
}
|
46
46
|
```
|
47
|
+
### スタートコルーチンが書かれているscript
|
47
48
|
|
49
|
+
```ここに言語名を入力
|
50
|
+
using UnityEngine;
|
51
|
+
using System.Collections;
|
52
|
+
using UnityEngine.UI;
|
53
|
+
|
54
|
+
public class ActionButton : MonoBehaviour
|
55
|
+
{
|
56
|
+
public float _mb;
|
57
|
+
public GameObject NotFixed;
|
58
|
+
public GameObject DestroyButton;
|
59
|
+
public GameObject GatheringButton;
|
60
|
+
public GameObject StopProcessingButton;
|
61
|
+
public GameObject Coniferous;
|
62
|
+
public GameObject Branches;
|
63
|
+
public float intarvar = 10.0f;
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
Slider _slider;
|
68
|
+
|
69
|
+
//中断するかどうかのフラグ
|
70
|
+
public bool Interruption;
|
71
|
+
|
72
|
+
//2倍減少中かのフラグ
|
73
|
+
private bool boost = false;
|
74
|
+
|
75
|
+
//標準の減少量
|
76
|
+
private float decreaseSpeed = 0.1f;
|
77
|
+
|
78
|
+
void Start()
|
79
|
+
{
|
80
|
+
// スライダーを取得する
|
81
|
+
_slider = GameObject.Find("CalorieSlider").GetComponent<Slider>();
|
82
|
+
|
83
|
+
StopProcessingButton.SetActive(false);
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
void Update()
|
88
|
+
{
|
89
|
+
if(boost)
|
90
|
+
{
|
91
|
+
_slider.value -= Time.deltaTime * decreaseSpeed * 10000.0f;
|
92
|
+
}
|
93
|
+
|
94
|
+
else
|
95
|
+
{
|
96
|
+
_slider.value -= Time.deltaTime * decreaseSpeed;
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
public void OnClick()
|
101
|
+
{
|
102
|
+
//Coniferous = GameObject.Find("Coniferous");
|
103
|
+
//Renderer ConiferousRenderer = Coniferous.GetComponent<Renderer>();
|
104
|
+
//Destroy(Coniferous);
|
105
|
+
StartCoroutine("ExecutionTime");
|
106
|
+
//ConiferousRenderer.enabled = false;
|
107
|
+
//Instantiate(Branches, transform.position, Quaternion.identity);
|
108
|
+
//DestroyButton.SetActive(false);
|
109
|
+
//GatheringButton.SetActive(false);
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
IEnumerator ExecutionTime()
|
114
|
+
{
|
115
|
+
|
116
|
+
|
117
|
+
DestroyButton.SetActive(false);
|
118
|
+
GatheringButton.SetActive(false);
|
119
|
+
|
120
|
+
StopProcessingButton.SetActive(true);
|
121
|
+
|
122
|
+
boost = true;
|
123
|
+
|
124
|
+
yield return new WaitForSeconds(5.0f);
|
125
|
+
|
126
|
+
boost = false;
|
127
|
+
|
128
|
+
|
129
|
+
StopProcessingButton.SetActive(false);
|
130
|
+
//Debug.Log("ok");
|
131
|
+
|
132
|
+
//GameObject.Find("DestroyButton").GetComponent<Image>().enabled = false;
|
133
|
+
gameObject.SetActive(false);
|
134
|
+
}
|
135
|
+
|
136
|
+
}
|
137
|
+
```
|
48
138
|
### 試したこと
|
49
139
|
|
50
|
-
コールチンを行っているscriptを付けているオブジェクトを、コルーチンを止めたいscriptの方で取得して
|
51
140
|
|
52
|
-
|
141
|
+
ボタンが押されたときにActionButtonスクリプトのコルーチンをStopCoroutine()で止まるはずが止まらず
|
53
|
-
|
54
142
|
### 補足情報(FW/ツールのバージョンなど)
|
55
143
|
|
56
144
|
Unity 2018.1.0f2
|
1
scriptにStopCoroutinを追加した処理を追記しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -20,25 +20,27 @@
|
|
20
20
|
public class InterruptionButtonScr : MonoBehaviour {
|
21
21
|
|
22
22
|
GameObject Coniferous;
|
23
|
-
|
23
|
+
GameObject ActionButton;
|
24
|
+
|
24
25
|
// Use this for initialization
|
25
|
-
void Start
|
26
|
+
void Start()
|
27
|
+
{
|
26
28
|
Coniferous = GameObject.Find("Coniferous");
|
27
|
-
}
|
28
|
-
|
29
|
-
// Update is called once per frame
|
30
|
-
void Update () {
|
31
|
-
ActionButton
|
29
|
+
ActionButton = GameObject.Find("ActionButton");
|
32
30
|
}
|
33
31
|
|
32
|
+
// Update is called once per frame
|
33
|
+
void Update()
|
34
|
+
{
|
35
|
+
|
36
|
+
|
37
|
+
}
|
38
|
+
|
34
39
|
public void OnClick()
|
35
40
|
{
|
41
|
+
ActionButton di = GetComponent<ActionButton>();
|
36
42
|
|
37
|
-
|
43
|
+
StopCoroutine("ExecutionTime");
|
38
|
-
//{
|
39
|
-
// yield break;
|
40
|
-
//}
|
41
|
-
|
42
44
|
}
|
43
45
|
}
|
44
46
|
```
|