ダメージを与えてHPが0になったら敵の攻撃を止めさせたいですが上手く行きません。
エラーも出ず。
HPが0になったらオブジェクトが消えるコードの例は沢山あるので流用してみましたが上手く行きません。
よろしくお願いします。
using
1using System.Collections.Generic; 2using UnityEngine; 3public class Health : MonoBehaviour 4{ 5 public const int maxHealth = 10; 6 public int currentHealth = maxHealth; 7 8 9 public void TakeDamage(int amount) 10 { 11 currentHealth -= amount; 12 if (currentHealth <= 0) 13 { 14 15 //コンポーネントを取得 16 EnemyFireMissileB component = this.gameObject.GetComponent<EnemyFireMissileB>(); 17 // 指定したコンポーネントを削除 18 Destroy(component); 19 20 } 21 } 22}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/20 15:42