今、ブロック崩しのゲームを作っているのですが、背景スクロールのため、GameObject(プレファブ)のサイズを取得したいと考え、下記サイトを参考にプログラムを組んだのですが、サイズの情報が上手く取得出来ず困っています。
何卒、ご教授の程、よろしくお願いします。
http://robamemo.hatenablog.com/entry/2017/07/31/182855
コード using System.Collections; using System.Collections.Generic; using UnityEngine; public class T_Scroll1 : MonoBehaviour { private GameObject b_g; [SerializeField] private float poswidth; // Use this for initialization void Start () { b_g = gameObject.transform.Find("background_front_fab").gameObject;// poswidth = b_g.GetComponent<RectTransform>().sizeDelta.y; } // Update is called once per frame void Update () { if (transform.position.y <= -11.0f) { transform.position = new Vector3(0, 11.0f, 0); } else { transform.Translate(0, -0.1f, 0); } } }
このスクリプトは、back_ground_block_fabにアタッチしています。
NullReferenceException: Object reference not set to an instance of an object
T_Scroll1.Start () (at Assets/T_Scroll1.cs:16)
エラーから、Objectが、Find出来ていないとまでは、解るのですが。
何卒よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/17 10:53 編集
2018/05/17 12:50
2018/05/18 13:42