###前提・実現したいこと
横スクロールシューティングを製作中で自機から右方向に弾オブジェクトが発射され、一定距離たつと弾オブジェクトが左向きに壁のオブジェクトになって流れる
###発生している問題・エラーメッセージ
NullReferenceException: Object reference not set to an instance of an object BulletController.Update () (at Assets/BulletController.cs:30)
###該当のソースコード
using System.Collections; using System.Collections.Generic; using UnityEngine; public class BulletController : MonoBehaviour { private float timer; bool m_xPlus = true; //public GameObject bulletPrefab; //public GameObject OilWall; //public Sprite aburabulet; // Use this for initialization void Start() { timer = 0.0f;//タイマー初期化 } // Update is called once per frame void Update() { timer += Time.deltaTime; //Vector2 Position = transform.localPosition; //SpriteRenderer renderer = gameObject.GetComponent<SpriteRenderer>(); if (m_xPlus == true) { //壁オブジェクトを非表示 GameObject gameObject = GameObject.Find("OilWall"); gameObject.SetActive(false); transform.Translate(0.2f, 0.0f, 0, Space.Self); if (timer >= 1.0f) m_xPlus = false; } else { //弾オブジェクトを非表示 GameObject gameObject = GameObject.Find("Bullet"); gameObject.SetActive(false); //壁オブジェクトを表示 GameObject oilbullet = this.transform.Find("OilWall").gameObject; oilbullet.SetActive(true); //renderer.sprite = aburabulet; transform.Translate(-0.05f, 0.0f, 0, Space.Self); if (timer >= 10.5f) m_xPlus = false; } if (timer >= 20.5f) { Destroy(gameObject); } } void OnTriggerEnter2D(Collider2D coll) { if (coll.gameObject.tag == "Enemy") { Destroy(this.gameObject); } } }
###試したこと
弾オブジェクトと壁オブジェクトの切り替えを表示・非表示で実装してみたが上手くいきません
###補足情報(言語/FW/ツール等のバージョンなど)
C# Unity 5.5.2f1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/19 16:41
2017/11/20 01:01