###実現したい内容
オブジェクト"First"(スクリプト"First"をアタッチされている)のみが表示されている状態で画面をクリックした際に
- オブジェクト"First"を破壊したい
- オブジェクト"Second"を生成したい
※オブジェクト"Second"はPrefab化済み
※eventsystemあり
発生している問題・エラーメッセージ
以下のエラーメッセージが表示されてゲームが停止する。
UnassignedReferenceException: The variable Second of First has not been assigned. You probably need to assign the Second variable of the First script in the inspector. UnityEngine.Object.Internal_InstantiateSingle (UnityEngine.Object data, UnityEngine.Vector3 pos, UnityEngine.Quaternion rot) <0x3fd5f900 + 0x00062> in <dc10dd4ad9f34aa98e691e49a48c7111>:0 UnityEngine.Object.Instantiate (UnityEngine.Object original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.bindings.cs:211) UnityEngine.Object.Instantiate[T] (T original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.bindings.cs:285) First.Update () (at Assets/C#/First.cs:13)
該当のソースコード
C#
1using System; 2using System.Collections; 3using System.Collections.Generic; 4using UnityEngine; 5 6public class First : MonoBehaviour 7{ 8 public GameObject Second; 9 void Update() 10 { 11 if (Input.GetMouseButton(0)) 12 { 13 Instantiate(original: Second, position: new Vector3(0.0f, 0.0f, 0.0f), rotation: Quaternion.identity); 14 Destroy(gameObject); 15 } 16 } 17 18}
試したこと

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/20 05:01