###前提・実現したいこと
unity初心者ながら失礼します。
unity scriptで、戦車ゲームを作成しており、自身の撃った砲弾が着弾した地点にヒットエフェクトを発生させたいと思っております。
###発生している問題・エラーメッセージ
しかし、実際は砲弾が当たっても跳ね返るのみで、ヒットエフェクトどころか自身の削除も出来ていない体たらく。 どなたか助言いただけないでしょうか。
###該当のソースコード
C#
1using UnityEngine; 2using System.Collections; 3public class BalletryTurn: MonoBehaviour { 4 5 public Transform Player; 6 public GameObject Muzzle1; 7 public GameObject Muzzle2; 8 public GameObject Exprode; 9 public float ReactionRange; 10 public float TurnSpeed; 11 public int _HP; 12 public static Vector3 Direction; 13 public static float dis; 14 public float EShotFlame; 15 private float EShotTime1; 16 // Use this for initialization 17 void Start () { 18 Player = GameObject.FindGameObjectWithTag("Player").transform; 19 Muzzle1 = GameObject.Find("Muzzle1"); 20 Muzzle2 = GameObject.Find("Muzzle2"); 21 } 22 23 // Update is called once per frame 24 void Update () { 25 EShotTime1 += Time.deltaTime;//砲弾射撃レート 26 27 EnemyShot enemyshot1=Muzzle1.GetComponent<EnemyShot>();//射撃メソッド取り込み 28 EnemyShot enemyshot2 = Muzzle2.GetComponent<EnemyShot>(); 29 Direction=Player.transform.position-transform.position;//回転方向計算 30 var rotation=Quaternion.LookRotation(Direction); 31 32 Vector3 PlayerPos = Player.position; 33 dis = Vector3.Distance(PlayerPos, transform.position); 34; 35 rotation.x = rotation.z = 0;//Y軸方向のみ回転させる 36 if (dis < ReactionRange)//一定範囲内にプレイヤーが近づいたら 37 { 38 transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * TurnSpeed);//砲台回転処理 39 if(EShotTime1>EShotFlame)//射撃 40 { 41 enemyshot1.EShot(Muzzle1.transform); 42 enemyshot2.EShot( Muzzle2.transform); 43 EShotTime1=0; 44 } 45 46 } 47 48 49 50 51 } 52 void Hit(Collider col)//弾がヒットしたら 53 { 54 if (col.gameObject.tag == "NShell")//ノーマル弾 55 { 56 57 _HP -= 3; 58 Destroy(col.gameObject); 59 if (_HP <= 0) 60 { 61 Instantiate(Exprode, new Vector3(transform.position.x, transform.position.y, transform.position.z), Quaternion.identity); 62 Destroy(this.gameObject); 63 } 64 } 65 if(col.gameObject.tag=="FShell")//火炎弾 66 { 67 _HP -= 2; 68 Destroy(col.gameObject); 69 if (_HP <= 0) 70 { 71 Instantiate(Exprode, new Vector3(transform.position.x, transform.position.y, transform.position.z), Quaternion.identity); 72 Destroy(this.gameObject); 73 } 74 } 75 if(col.gameObject.tag=="AShell")//水弾 76 { 77 _HP -= 5; 78 Destroy(col.gameObject); 79 if (_HP <= 0) 80 { 81 Instantiate(Exprode, new Vector3(transform.position.x, transform.position.y, transform.position.z), Quaternion.identity); 82 Destroy(this.gameObject); 83 } 84 } 85 } 86}
###試したこと
砲弾本体に実装すべきかどうか等も検討しましたが、こちらも上手くいきませんでした。
Updateに_HPが0以下になった場合も試しましたがこれもダメでした。
###補足情報(言語/FW/ツール等のバージョンなど)
visual studioを使用
ソースコードはヒット目標物に当てています。
回答1件
あなたの回答
tips
プレビュー