Unityで自作のシューティングゲームを作っているのですがHPと弾の攻撃力を実装するためにはどういうようなプログラムをューティングゲームを作っているのですがHPと弾の攻撃力を実装するためにはどういうようなプログラムを書けばいいでしょうか?
今のところ下記のようなプログラムを書いています
using System.Collections; using System.Collections.Generic; using UnityEngine; public class RockController : MonoBehaviour { public int hp = 10; public GameObject explosionPrefab; float fallSpeed; float rotSpeed; // Use this for initialization void Start () { this.fallSpeed = 0.01f + 0.1f * Random.value; this.rotSpeed = 5f + 3f * Random.value; } // Update is called once per frame void Update () { transform.Translate(-fallSpeed, 0, 0, Space.World); transform.Rotate(0, 0, rotSpeed ); if (transform.position.x < -12f) { Destroy (gameObject); } } // 他のオブジェクトと衝突した時に呼び出される関数 private void OnTriggerEnter2D( Collider2D collision ) { string yourTag = collision.gameObject.tag; // 弾と衝突した場合 if ( yourTag == "bulletPrefab" ) { // 弾を削除する Destroy( collision.gameObject ); hp = hp - bulletPrefab.power; if (hp <= 0) { // 敵を削除する Destroy(gameObject); } } // ロケットと衝突した場合 if ( collision.name.Contains( "rocket" ) ) { // 弾を削除する Destroy( collision.gameObject ); // 敵を削除する Destroy(gameObject); //GameObject.Find ("Canvas").GetComponent<UIController> ().GameOver (); } // ロケットと衝突した場合 if ( collision.name.Contains( "saport" ) ) { // 弾を削除する Destroy( collision.gameObject ); // 敵を削除する Destroy( gameObject ); } // ロケットと衝突した場合 { if ( yourTag == "bomb" ) // 弾を削除する Destroy( collision.gameObject ); // 敵を削除する Destroy( gameObject ); //GameObject.Find ("Canvas").GetComponent<UIController> ().AddScore (); } Instantiate (explosionPrefab, transform.position, Quaternion.identity); Destroy (gameObject); } }
現在書いているコードを追加しました