質問編集履歴

1

コードを記載しました

2021/09/03 14:20

投稿

kitasan830
kitasan830

スコア8

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,80 @@
1
1
  現在Unityでオリジナルゲームの開発中で、プレイヤーが透明な壁を通り抜けたら、敵が動き、20秒後にdestroyされるというコードを書いて実際に動いてくれたのですが、20秒経って破壊されると以下の画像のとおりエラーが出てしまいます。
2
2
 
3
3
  解決方法を教えていただきたいです。
4
+
5
+
6
+
7
+ 追伸 コードはこちらになります。
8
+
9
+ using System.Collections;
10
+
11
+ using System.Collections.Generic;
12
+
13
+ using UnityEngine;
14
+
15
+ using UnityEngine.UI;
16
+
17
+
18
+
19
+ public class EnemyController : MonoBehaviour
20
+
21
+ {
22
+
23
+ public float speed;
24
+
25
+ public bool Driving = false;
26
+
27
+ public GameObject car;
28
+
29
+
30
+
31
+ void Start()
32
+
33
+ {
34
+
35
+ }
36
+
37
+ void Update()
38
+
39
+ {
40
+
41
+ if(Driving == true)
42
+
43
+ {
44
+
45
+ car.transform.position -= new Vector3(speed * Time.deltaTime, 0, 0);
46
+
47
+ Destroy(car, 20f);
48
+
49
+ }
50
+
51
+ }
52
+
53
+
54
+
55
+ void OnTriggerEnter(Collider col)
56
+
57
+ {if(col.gameObject.tag == "Player")
58
+
59
+ {
60
+
61
+ Driving = true;
62
+
63
+ }
64
+
65
+
66
+
67
+ }
68
+
69
+
70
+
71
+
72
+
73
+ }
74
+
75
+
76
+
77
+
4
78
 
5
79
 
6
80