質問編集履歴
2
書式の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,234 +8,228 @@
|
|
8
8
|
|
9
9
|
### 発生している問題・エラーメッセージ
|
10
10
|
|
11
|
-
|
11
|
+
![イメージ説明](56c6013adad7856890551b520a8982b1.png)
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
### 該当のソースコード
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
```ここに言語名を入力
|
20
|
+
|
21
|
+
using System.Collections;
|
22
|
+
|
23
|
+
using System.Collections.Generic;
|
24
|
+
|
25
|
+
using UnityEngine;
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
public class WallSpawner : MonoBehaviour
|
30
|
+
|
31
|
+
{
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
public bool isActive = false;
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
[SerializeField]
|
40
|
+
|
41
|
+
GameObject wallPrefab = null;
|
42
|
+
|
43
|
+
[SerializeField, Min(0.1f)]
|
44
|
+
|
45
|
+
float defaultMinWaitTime = 1;
|
46
|
+
|
47
|
+
[SerializeField, Min(0.1f)]
|
48
|
+
|
49
|
+
float defaultMaxWaitTime = 1;
|
50
|
+
|
51
|
+
[SerializeField]
|
52
|
+
|
53
|
+
Vector2 defaultMinSize = Vector2.one;
|
54
|
+
|
55
|
+
[SerializeField]
|
56
|
+
|
57
|
+
Vector2 defaultMaxSize = Vector2.one;
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
bool isSpawning = false;
|
62
|
+
|
63
|
+
float minWaitTime;
|
64
|
+
|
65
|
+
float maxWaitTime;
|
66
|
+
|
67
|
+
Vector2 minSize;
|
68
|
+
|
69
|
+
Vector2 maxSize;
|
70
|
+
|
71
|
+
Coroutine timer;
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
//外部から値を代入するためのプロパティ
|
76
|
+
|
77
|
+
public float MinWaitTime
|
78
|
+
|
79
|
+
{
|
80
|
+
|
81
|
+
set
|
82
|
+
|
83
|
+
{
|
84
|
+
|
85
|
+
//あまりにも小さい値になるとものすごい数の障害物が生成されてしまうので、0.1未満にならないようにする
|
86
|
+
|
87
|
+
minWaitTime = Mathf.Max(value, 0.1f);
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
get
|
92
|
+
|
93
|
+
{
|
94
|
+
|
95
|
+
return minWaitTime;
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
public float MaxWaitTime
|
104
|
+
|
105
|
+
{
|
106
|
+
|
107
|
+
set
|
108
|
+
|
109
|
+
{
|
110
|
+
|
111
|
+
maxWaitTime = Mathf.Max(value, 0.1f);
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
get
|
116
|
+
|
117
|
+
{
|
118
|
+
|
119
|
+
return maxWaitTime;
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
void Start()
|
128
|
+
|
129
|
+
{
|
130
|
+
|
131
|
+
InitSpawner();
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
void Update()
|
138
|
+
|
139
|
+
{
|
140
|
+
|
141
|
+
if (!isActive)
|
142
|
+
|
143
|
+
{
|
144
|
+
|
145
|
+
//生成中なら中断する
|
146
|
+
|
147
|
+
if(timer != null)
|
148
|
+
|
149
|
+
{
|
150
|
+
|
151
|
+
StopCoroutine(timer);
|
152
|
+
|
153
|
+
isSpawning = false;
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
return;
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
//生成中じゃないなら生成開始
|
166
|
+
|
167
|
+
if (!isSpawning)
|
168
|
+
|
169
|
+
{
|
170
|
+
|
171
|
+
timer = StartCoroutine("SpawnTimer");
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
//初期化用メソッド
|
180
|
+
|
181
|
+
public void InitSpawner()
|
182
|
+
|
183
|
+
{
|
184
|
+
|
185
|
+
minWaitTime = defaultMinWaitTime;
|
186
|
+
|
187
|
+
maxWaitTime = defaultMaxWaitTime;
|
188
|
+
|
189
|
+
minSize = defaultMinSize;
|
190
|
+
|
191
|
+
maxSize = defaultMaxSize;
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
//生成処理を行うコルーチン
|
198
|
+
|
199
|
+
IEnumerator SpawnTimer()
|
200
|
+
|
201
|
+
{
|
202
|
+
|
203
|
+
isSpawning = true;
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
GameObject wallObj = Instantiate(wallPrefab, transform.position, Quaternion.identity);
|
208
|
+
|
209
|
+
Wall wall = wallObj.GetComponent<Wall>();
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
float sizeX = Random.Range(minSize.x, maxSize.x);
|
214
|
+
|
215
|
+
float sizeY = Random.Range(minSize.y, maxSize.y);
|
216
|
+
|
217
|
+
wall.SetWall(new Vector2(sizeX, sizeY));
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
float waitTime = Random.Range(minWaitTime, maxWaitTime);
|
222
|
+
|
223
|
+
yield return new WaitForSeconds(waitTime);
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
isSpawning = false;
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
}
|
12
234
|
|
13
235
|
```
|
14
|
-
|
15
|
-
![イメージ説明](56c6013adad7856890551b520a8982b1.png)
|
16
|
-
|
17
|
-
```
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
### 該当のソースコード
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
```ここに言語名を入力
|
26
|
-
|
27
|
-
using System.Collections;
|
28
|
-
|
29
|
-
using System.Collections.Generic;
|
30
|
-
|
31
|
-
using UnityEngine;
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
public class WallSpawner : MonoBehaviour
|
36
|
-
|
37
|
-
{
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
public bool isActive = false;
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
[SerializeField]
|
46
|
-
|
47
|
-
GameObject wallPrefab = null;
|
48
|
-
|
49
|
-
[SerializeField, Min(0.1f)]
|
50
|
-
|
51
|
-
float defaultMinWaitTime = 1;
|
52
|
-
|
53
|
-
[SerializeField, Min(0.1f)]
|
54
|
-
|
55
|
-
float defaultMaxWaitTime = 1;
|
56
|
-
|
57
|
-
[SerializeField]
|
58
|
-
|
59
|
-
Vector2 defaultMinSize = Vector2.one;
|
60
|
-
|
61
|
-
[SerializeField]
|
62
|
-
|
63
|
-
Vector2 defaultMaxSize = Vector2.one;
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
bool isSpawning = false;
|
68
|
-
|
69
|
-
float minWaitTime;
|
70
|
-
|
71
|
-
float maxWaitTime;
|
72
|
-
|
73
|
-
Vector2 minSize;
|
74
|
-
|
75
|
-
Vector2 maxSize;
|
76
|
-
|
77
|
-
Coroutine timer;
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
//外部から値を代入するためのプロパティ
|
82
|
-
|
83
|
-
public float MinWaitTime
|
84
|
-
|
85
|
-
{
|
86
|
-
|
87
|
-
set
|
88
|
-
|
89
|
-
{
|
90
|
-
|
91
|
-
//あまりにも小さい値になるとものすごい数の障害物が生成されてしまうので、0.1未満にならないようにする
|
92
|
-
|
93
|
-
minWaitTime = Mathf.Max(value, 0.1f);
|
94
|
-
|
95
|
-
}
|
96
|
-
|
97
|
-
get
|
98
|
-
|
99
|
-
{
|
100
|
-
|
101
|
-
return minWaitTime;
|
102
|
-
|
103
|
-
}
|
104
|
-
|
105
|
-
}
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
public float MaxWaitTime
|
110
|
-
|
111
|
-
{
|
112
|
-
|
113
|
-
set
|
114
|
-
|
115
|
-
{
|
116
|
-
|
117
|
-
maxWaitTime = Mathf.Max(value, 0.1f);
|
118
|
-
|
119
|
-
}
|
120
|
-
|
121
|
-
get
|
122
|
-
|
123
|
-
{
|
124
|
-
|
125
|
-
return maxWaitTime;
|
126
|
-
|
127
|
-
}
|
128
|
-
|
129
|
-
}
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
void Start()
|
134
|
-
|
135
|
-
{
|
136
|
-
|
137
|
-
InitSpawner();
|
138
|
-
|
139
|
-
}
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
void Update()
|
144
|
-
|
145
|
-
{
|
146
|
-
|
147
|
-
if (!isActive)
|
148
|
-
|
149
|
-
{
|
150
|
-
|
151
|
-
//生成中なら中断する
|
152
|
-
|
153
|
-
if(timer != null)
|
154
|
-
|
155
|
-
{
|
156
|
-
|
157
|
-
StopCoroutine(timer);
|
158
|
-
|
159
|
-
isSpawning = false;
|
160
|
-
|
161
|
-
}
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
return;
|
166
|
-
|
167
|
-
}
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
//生成中じゃないなら生成開始
|
172
|
-
|
173
|
-
if (!isSpawning)
|
174
|
-
|
175
|
-
{
|
176
|
-
|
177
|
-
timer = StartCoroutine("SpawnTimer");
|
178
|
-
|
179
|
-
}
|
180
|
-
|
181
|
-
}
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
//初期化用メソッド
|
186
|
-
|
187
|
-
public void InitSpawner()
|
188
|
-
|
189
|
-
{
|
190
|
-
|
191
|
-
minWaitTime = defaultMinWaitTime;
|
192
|
-
|
193
|
-
maxWaitTime = defaultMaxWaitTime;
|
194
|
-
|
195
|
-
minSize = defaultMinSize;
|
196
|
-
|
197
|
-
maxSize = defaultMaxSize;
|
198
|
-
|
199
|
-
}
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
//生成処理を行うコルーチン
|
204
|
-
|
205
|
-
IEnumerator SpawnTimer()
|
206
|
-
|
207
|
-
{
|
208
|
-
|
209
|
-
isSpawning = true;
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
GameObject wallObj = Instantiate(wallPrefab, transform.position, Quaternion.identity);
|
214
|
-
|
215
|
-
Wall wall = wallObj.GetComponent<Wall>();
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
float sizeX = Random.Range(minSize.x, maxSize.x);
|
220
|
-
|
221
|
-
float sizeY = Random.Range(minSize.y, maxSize.y);
|
222
|
-
|
223
|
-
wall.SetWall(new Vector2(sizeX, sizeY));
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
float waitTime = Random.Range(minWaitTime, maxWaitTime);
|
228
|
-
|
229
|
-
yield return new WaitForSeconds(waitTime);
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
isSpawning = false;
|
234
|
-
|
235
|
-
}
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
}
|
240
|
-
|
241
|
-
```
|
1
タグの追加
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|