Unity初心者です。
今、ゲーム背景画像を2枚用意して、背景スクロールをしたいのですが、画像のように切れ目が発生します。
そこで、コードからゲーム背景画像1の高さを獲得し、背景画像2のポジションをスクリプトから作りたいと、考え、下記コードをつくりました。
[SerializeField] private GameObject b_g; [SerializeField] private GameObject b_g2; [SerializeField] private float poshegiht; [SerializeField] private Vector2 pos2; // Use this for initialization void Start () { b_g = transform.parent.Find("background_back_fab").gameObject; b_g2 = transform.parent.Find("background_back_fab2").gameObject; poshegiht = b_g.GetComponent<SpriteRenderer>().bounds.size.y; pos2 = GameObject.Find("background_back_fab2").transform.position; GameObject.Find("background_back_fab2").transform.position = new Vector2(pos2.x , pos2.y + poshegiht); } // Update is called once per frame void Update () { if (transform.position.y <= -1 * poshegiht) { // transform.position = new Vector3(0, 11.0f, 0); transform.position = new Vector2(0, poshegiht); } else { transform.Translate(0, -0.0250f, 0); } } }
アドバイスの程、よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/23 00:16
2018/05/23 02:32
2018/05/23 02:33