前提・実現したいこと
Unityを使用。
GameClearのUIがでたあと、矢印ダメージを受けないようにするための処理を実装したい。
発生している問題・エラーメッセージ
GameClearのUIがでたあと、矢印ダメージを受けてしまう。
そのためHPゲージが0になりGameOverのUIが重ねて表示されてしまう。
該当のソースコード
C# ゲームエンジン:Unity
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; //UIを使うので忘れずに追加! public class GameDirector : MonoBehaviour { GameObject hpGauge; public GameObject GameOverPanel; public GameObject GameClearPanel; private GameObject distance; public Image hpgaugeimage; public float gametimer; private int timeup; public bool no_damage; // Start is called before the first frame update void Start() { this.hpGauge = GameObject.Find("hpGauge"); distance = GameObject.Find("Timer"); gametimer = 10.0f; no_damage = false; timeup = 1; } public void DecreaseHp() { hpgaugeimage.fillAmount -= 0.2f; no_damage = false; if (hpgaugeimage.fillAmount == 0)//ゲージ0になったあと矢印に当たらないとGameOver出ない { Debug.Log("GameOver"); GameOverPanel.SetActive(true); timeup = 0; } } // Update is called once per frame void Update() { gametimer -= Time.deltaTime * timeup; distance.GetComponent<Text>().text = "残り" + gametimer.ToString("F1") + "秒"; //-0.01になったりならなかったりする。(F) 常に-0.01(F2) if ((hpgaugeimage.fillAmount > 0) && (gametimer <= 1))//Clear後に矢印ダメージ受けないようにするために? { if ((gametimer < 0) && (no_damage = true)) { Debug.Log("GameClear"); GameClearPanel.SetActive(true); timeup = 0; hpgaugeimage.fillAmount += 0.1f; }
試したこと
①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
まだ回答がついていません
会員登録して回答してみよう