質問編集履歴

2

おういえす

2020/12/25 08:29

投稿

Um_kok
Um_kok

スコア39

test CHANGED
File without changes
test CHANGED
@@ -134,6 +134,146 @@
134
134
 
135
135
  ```
136
136
 
137
+ 敵のAIのコード
138
+
139
+ ```C#
140
+
141
+ using System.Collections;
142
+
143
+ using System.Collections.Generic;
144
+
145
+ using UnityEngine;
146
+
147
+ using UnityEngine.AI;
148
+
149
+
150
+
151
+ public class CarAI : MonoBehaviour
152
+
153
+ {
154
+
155
+ [SerializeField, Header("通過点")] private Transform[] passingPoint;
156
+
157
+ private NavMeshAgent nav;
158
+
159
+ private int pointNumber = 0;
160
+
161
+
162
+
163
+ void Start()
164
+
165
+ {
166
+
167
+ nav = GetComponent<NavMeshAgent>();
168
+
169
+ nav.SetDestination(passingPoint[pointNumber].position);
170
+
171
+ }
172
+
173
+
174
+
175
+ private void OnTriggerEnter(Collider other)
176
+
177
+ {
178
+
179
+ // 目的地を設定
180
+
181
+ if (other.gameObject.CompareTag("PassingPoint0"))
182
+
183
+ {
184
+
185
+ pointNumber = 1;
186
+
187
+ nav.SetDestination(passingPoint[pointNumber].position);
188
+
189
+ }
190
+
191
+ else if (other.gameObject.CompareTag("PassingPoint1"))
192
+
193
+ {
194
+
195
+ pointNumber = 2;
196
+
197
+ nav.SetDestination(passingPoint[pointNumber].position);
198
+
199
+ }
200
+
201
+ else if (other.gameObject.CompareTag("PassingPoint2"))
202
+
203
+ {
204
+
205
+ pointNumber = 3;
206
+
207
+ nav.SetDestination(passingPoint[pointNumber].position);
208
+
209
+ }
210
+
211
+ else if (other.gameObject.CompareTag("PassingPoint3"))
212
+
213
+ {
214
+
215
+ pointNumber = 4;
216
+
217
+ nav.SetDestination(passingPoint[pointNumber].position);
218
+
219
+ }
220
+
221
+ else if (other.gameObject.CompareTag("PassingPoint4"))
222
+
223
+ {
224
+
225
+ pointNumber = 5;
226
+
227
+ nav.SetDestination(passingPoint[pointNumber].position);
228
+
229
+ }
230
+
231
+ else if (other.gameObject.CompareTag("PassingPoint5"))
232
+
233
+ {
234
+
235
+ pointNumber = 6;
236
+
237
+ nav.SetDestination(passingPoint[pointNumber].position);
238
+
239
+ }
240
+
241
+ else if (other.gameObject.CompareTag("PassingPoint6"))
242
+
243
+ {
244
+
245
+ pointNumber = 7;
246
+
247
+ nav.SetDestination(passingPoint[pointNumber].position);
248
+
249
+ }
250
+
251
+ else if (other.gameObject.CompareTag("PassingPoint7"))
252
+
253
+ {
254
+
255
+ pointNumber = 8;
256
+
257
+ nav.SetDestination(passingPoint[pointNumber].position);
258
+
259
+ }
260
+
261
+ else if (other.gameObject.CompareTag("PassingPoint8"))
262
+
263
+ {
264
+
265
+ pointNumber = 0;
266
+
267
+ nav.SetDestination(passingPoint[pointNumber].position);
268
+
269
+ }
270
+
271
+ }
272
+
273
+ }
274
+
275
+ ```
276
+
137
277
  **やった事**
138
278
 
139
279
  参考サイト

1

おういえす

2020/12/25 08:29

投稿

Um_kok
Um_kok

スコア39

test CHANGED
File without changes
test CHANGED
@@ -136,6 +136,14 @@
136
136
 
137
137
  **やった事**
138
138
 
139
+ 参考サイト
140
+
141
+ [NavMeshAgent .Resume](https://translate.google.com/translate?hl=ja&sl=en&u=https://docs.unity3d.com/540/Documentation/ScriptReference/NavMeshAgent.Stop.html&prev=search&pto=aue)
142
+
143
+ [NavMeshAgent .Stop](https://translate.google.com/translate?hl=ja&sl=en&u=https://docs.unity3d.com/540/Documentation/ScriptReference/NavMeshAgent.Stop.html&prev=search&pto=aue)
144
+
145
+
146
+
139
147
  そこでアイテムを作成しようとして、調べて実装してみました
140
148
 
141
149
  アイテムに当たったら、スピードをゆっくり落として、一定時間たったら、また再開するというコードを書きました。なのですが、いくつかできておらず、教えてもらいたいです。