回答編集履歴
2
誤字修正
test
CHANGED
@@ -24,7 +24,7 @@
|
|
24
24
|
|
25
25
|
|
26
26
|
|
27
|
-
public class
|
27
|
+
public class First : MonoBehaviour {
|
28
28
|
|
29
29
|
public GameObject Second;
|
30
30
|
|
1
補足
test
CHANGED
@@ -5,3 +5,53 @@
|
|
5
5
|
Error的にはオブジェクトにプレハブがアタッチされてない可能性があるので
|
6
6
|
|
7
7
|
Hierarchy上で配置されている``First``オブジェクトに、ちゃんとSecondのプレハブがアタッチされているか確認してみてください。
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
もしくはスクリプトを少し書き加えてデバッグログを見ながらチェックしてみてください。
|
12
|
+
|
13
|
+
プレハブがアタッチされていないと「null」と表示されます。
|
14
|
+
|
15
|
+
```C#
|
16
|
+
|
17
|
+
using System;
|
18
|
+
|
19
|
+
using System.Collections;
|
20
|
+
|
21
|
+
using System.Collections.Generic;
|
22
|
+
|
23
|
+
using UnityEngine;
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
public class test : MonoBehaviour {
|
28
|
+
|
29
|
+
public GameObject Second;
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
private void Start() {
|
34
|
+
|
35
|
+
Debug.Log(Second); // アタッチされているか確認
|
36
|
+
|
37
|
+
}
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
void Update() {
|
42
|
+
|
43
|
+
if (Input.GetMouseButton(0)) {
|
44
|
+
|
45
|
+
Instantiate(original: Second, position: new Vector3(0.0f, 0.0f, 0.0f), rotation: Quaternion.identity);
|
46
|
+
|
47
|
+
Destroy(gameObject);
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
```
|