前提・実現したいこと
Unityを使用。
GameClearのUIがでたあと、矢印ダメージを受けないようにするための処理を実装したい。
発生している問題・エラーメッセージ
GameClearのUIがでたあと、矢印ダメージを受けてしまう。
そのためHPゲージが0になりGameOverのUIが重ねて表示されてしまう。
該当のソースコード
C# ゲームエンジン:Unity
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; //UIを使うので忘れずに追加! 5 6public class GameDirector : MonoBehaviour 7{ 8 GameObject hpGauge; 9 public GameObject GameOverPanel; 10 public GameObject GameClearPanel; 11 private GameObject distance; 12 public Image hpgaugeimage; 13 public float gametimer; 14 private int timeup; 15 public bool no_damage; 16 17 18 // Start is called before the first frame update 19 void Start() 20 { 21 this.hpGauge = GameObject.Find("hpGauge"); 22 distance = GameObject.Find("Timer"); 23 gametimer = 10.0f; 24 no_damage = false; 25 timeup = 1; 26 } 27 28 public void DecreaseHp() 29 { 30 hpgaugeimage.fillAmount -= 0.2f; 31 no_damage = false; 32 33 if (hpgaugeimage.fillAmount == 0)//ゲージ0になったあと矢印に当たらないとGameOver出ない 34 { 35 Debug.Log("GameOver"); 36 GameOverPanel.SetActive(true); 37 timeup = 0; 38 } 39 40 41 } 42 43 // Update is called once per frame 44 void Update() 45 { 46 gametimer -= Time.deltaTime * timeup; 47 distance.GetComponent<Text>().text = "残り" + gametimer.ToString("F1") + "秒"; 48 //-0.01になったりならなかったりする。(F) 常に-0.01(F2) 49 50 51 if ((hpgaugeimage.fillAmount > 0) && (gametimer <= 1))//Clear後に矢印ダメージ受けないようにするために? 52 { 53 if ((gametimer < 0) && (no_damage = true)) 54 { 55 Debug.Log("GameClear"); 56 GameClearPanel.SetActive(true); 57 timeup = 0; 58 hpgaugeimage.fillAmount += 0.1f; 59 }
試したこと
①bool型の変数を宣言。
public bool no_damage;
②タイマーが0秒かつno_damageがtrueになったらfillAmountを減らさないように0.0fで減算および加算実施 → HPゲージ減る。
タイマーが0秒かつno_damageがtrueになったらfillAmountを+=0.1f or +=0.2で加算 →ダメージ受けないけど加算されるからゲージピコピコなる。
補足情報(FW/ツールのバージョンなど)
Unityのバージョン:2020.3.19f1
VisualStudio2019
回答1件
あなたの回答
tips
プレビュー