質問編集履歴
3
aa
test
CHANGED
File without changes
|
test
CHANGED
@@ -218,6 +218,8 @@
|
|
218
218
|
|
219
219
|
```
|
220
220
|
|
221
|
+
Attack.cs
|
222
|
+
|
221
223
|
using System.Collections;
|
222
224
|
|
223
225
|
using System.Collections.Generic;
|
@@ -244,7 +246,7 @@
|
|
244
246
|
|
245
247
|
boxCol = GetComponent<BoxCollider>();
|
246
248
|
|
247
|
-
player = GameObject.FindWithTag("En
|
249
|
+
player = GameObject.FindWithTag("Enemy");
|
248
250
|
|
249
251
|
}
|
250
252
|
|
2
s
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
MissingReferenceExceptionのエラーで困ってます
|
test
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
|
-
|
3
|
+
PlayerがEnemyの当たり判定に当たるとPlayerをデストロイさせたいんですが
|
4
|
-
|
4
|
+
|
5
|
-
|
5
|
+
MissingReferenceExceptionのエラーが出て途中で止まってしまいます。
|
6
|
-
|
6
|
+
|
7
|
-
必
|
7
|
+
ネットで調べたところNULLをする必要があるらしくどこに追加すればいいか分からなくて
|
8
|
+
|
9
|
+
変えてもエラーが出てしまいます。
|
10
|
+
|
11
|
+
|
8
12
|
|
9
13
|
|
10
14
|
|
@@ -211,3 +215,83 @@
|
|
211
215
|
}
|
212
216
|
|
213
217
|
```
|
218
|
+
|
219
|
+
```
|
220
|
+
|
221
|
+
using System.Collections;
|
222
|
+
|
223
|
+
using System.Collections.Generic;
|
224
|
+
|
225
|
+
using UnityEngine;
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
public class Attack : MonoBehaviour
|
230
|
+
|
231
|
+
{
|
232
|
+
|
233
|
+
public bool playerAttak;
|
234
|
+
|
235
|
+
private BoxCollider boxCol;
|
236
|
+
|
237
|
+
public GameObject player;
|
238
|
+
|
239
|
+
// Use this for initialization
|
240
|
+
|
241
|
+
void Start()
|
242
|
+
|
243
|
+
{
|
244
|
+
|
245
|
+
boxCol = GetComponent<BoxCollider>();
|
246
|
+
|
247
|
+
player = GameObject.FindWithTag("Enamy");
|
248
|
+
|
249
|
+
}
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
// Update is called once per frame
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
void OnTriggerStay(Collider col)
|
258
|
+
|
259
|
+
{
|
260
|
+
|
261
|
+
if (col.gameObject.tag == "Player")
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
{
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
playerAttack = true;
|
270
|
+
|
271
|
+
Destroy(gameObject);
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
}
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
```
|
284
|
+
|
285
|
+
```
|
286
|
+
|
287
|
+
エラー内容
|
288
|
+
|
289
|
+
MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
|
290
|
+
|
291
|
+
Your script should either check if it is null or you should not destroy the object.
|
292
|
+
|
293
|
+
UnityEngine.GameObject.GetComponent[search] () (at C:/buildslave/unity/build/artifacts/generated/common/runtime/GameObjectBindings.gen.cs:38)
|
294
|
+
|
295
|
+
Enemy.Update () (at Assets/Enemy.cs:33)
|
296
|
+
|
297
|
+
```
|
1
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|