弾が破壊されなくなったので破壊したい
現状・・・敵の弾が壁に当たって跳ね返る、エラーは出ていない
調べて試したこと・・・Triggerにしてみたり(現在はTriggeroff)Bulletタグをつけたりしてみた
壁
Unity
1public class Wall : MonoBehaviour 2{ 3 public float minHeight; 4 public float maxHeight; 5 public GameObject pivot; 6 7 // Start is called before the first frame update 8 void Start() 9 { 10 //開始時に隙間の高さを変更 11 ChangeHeight(); 12 } 13 14 // Update is called once per frame 15 void Update() 16 { 17 18 } 19 20 void ChangeHeight() 21 { 22 //ランダムに高さ変更して生成 23 float height = Random.Range(minHeight, maxHeight); 24 pivot.transform.localPosition = new Vector3(0.0f, height, 0.0f); 25 } 26 27 void OnScrollEnd() 28 { 29 ChangeHeight(); 30 } 31 32 void OnCollisionEnter(Collision col) 33 { 34 if (col.gameObject.CompareTag("Bullet")) 35 { 36 Destroy(gameObject); 37 } 38 } 39}
敵の射撃
Unity
1public class EnemyShot : MonoBehaviour 2{ 3 public GameObject bulletPrefabs; 4 public float shotSpeed; 5 public AudioClip shotSound; 6 private int count = 0; 7 8 // Start is called before the first frame update 9 void Start() 10 { 11 12 } 13 14 // Update is called once per frame 15 void Update() 16 { 17 count += 1; 18 //60フレームごとに発射 19 if (count % 60 == 0) 20 { 21 EnemyShot1(); 22 } 23 } 24 25 public void EnemyShot1() 26 { 27 GameObject bullet = Instantiate(bulletPrefabs, transform.position, Quaternion.identity) as GameObject; 28 Rigidbody bulletRigidbody = bullet.GetComponent<Rigidbody>(); 29 bulletRigidbody.AddForce(transform.forward * shotSpeed); 30 AudioSource.PlayClipAtPoint(shotSound, transform.position); 31 } 32 33} 34
敵の動き
Unity
1public class EnemyController : MonoBehaviour 2{ 3 private Vector3 targetpos; 4 5 void Start() 6 { 7 targetpos = transform.position; 8 } 9 10 11 // Update is called once per frame 12 void Update() 13 { 14 transform.position = new Vector3(targetpos.x, Mathf.Sin(Time.time) * 10.0f + targetpos.y, targetpos.z); 15 16 } 17} 18 19
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。