回答編集履歴
2
誤字修正
answer
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
using System.Collections.Generic;
|
12
12
|
using UnityEngine;
|
13
13
|
|
14
|
-
public class
|
14
|
+
public class First : MonoBehaviour {
|
15
15
|
public GameObject Second;
|
16
16
|
|
17
17
|
private void Start() {
|
1
補足
answer
CHANGED
@@ -1,4 +1,29 @@
|
|
1
1
|
ざっくりとテストしてみましたが、提示された条件とソースコードで特に問題なく動きました。
|
2
2
|
|
3
3
|
Error的にはオブジェクトにプレハブがアタッチされてない可能性があるので
|
4
|
-
Hierarchy上で配置されている``First``オブジェクトに、ちゃんとSecondのプレハブがアタッチされているか確認してみてください。
|
4
|
+
Hierarchy上で配置されている``First``オブジェクトに、ちゃんとSecondのプレハブがアタッチされているか確認してみてください。
|
5
|
+
|
6
|
+
もしくはスクリプトを少し書き加えてデバッグログを見ながらチェックしてみてください。
|
7
|
+
プレハブがアタッチされていないと「null」と表示されます。
|
8
|
+
```C#
|
9
|
+
using System;
|
10
|
+
using System.Collections;
|
11
|
+
using System.Collections.Generic;
|
12
|
+
using UnityEngine;
|
13
|
+
|
14
|
+
public class test : MonoBehaviour {
|
15
|
+
public GameObject Second;
|
16
|
+
|
17
|
+
private void Start() {
|
18
|
+
Debug.Log(Second); // アタッチされているか確認
|
19
|
+
}
|
20
|
+
|
21
|
+
void Update() {
|
22
|
+
if (Input.GetMouseButton(0)) {
|
23
|
+
Instantiate(original: Second, position: new Vector3(0.0f, 0.0f, 0.0f), rotation: Quaternion.identity);
|
24
|
+
Destroy(gameObject);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
}
|
29
|
+
```
|