unityでオブジェクトAをプレハブ化し
そのプレハブをInstantiateで量産して、オブジェクトBの座標と
同じ座標まで移動したら破壊する。
という、コード書いたつもりなのですが何故か以下のエラーが発生してしまいます。
UnassignedReferenceException: The variable LeftWall of BoneJump_R has not been assigned. You probably need to assign the LeftWall variable of the BoneJump_R script in the inspector.
ちゃんとSerializeFieldでオブジェクトをアタッチしていすはずなのですが…
何が原因なのでしょうか?
以下が書いたスクリプトです。
初心者のため拙いコードですが、ご了承ください。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class BoneJump_R : MonoBehaviour 6{ 7 [SerializeField] GameObject LeftWall; 8 9 private float speed = 2.5f; 10 // Start is called before the first frame update 11 void Start() 12 { 13 14 } 15 16 // Update is called once per frame 17 void Update() 18 { 19 this.transform.position += new Vector3(1.0f * Time.deltaTime * speed, 0.0f, 0.0f); 20 if(transform.position.x==LeftWall.transform.position.x) 21 { 22 Destroy(this); 23 } 24 } 25}
お詳しい方、教えていただければ大変助かります。
以上でございます。
回答1件
あなたの回答
tips
プレビュー