何度も実行してしまうものを一度だけ実行したいです。
ImageのFillAmountが1以上なら、Daimahouboolをtrueにすると書き込めば、一度だけ実行されると思ったのですがtrueの内容が何度も実行されてしまいます。
1以上なら常に実行されるようになっているために、何度も実行してしまうと思うのですが、1度だけ実行する方法を教えていただきたいです。
C#
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Playables; using UnityEngine.UI; public class DaimahouScript : MonoBehaviour { private bool Daimahoubool; public PlayableDirector director; public Image DaimahouGage; public GameObject DaimahouUI; public GameObject Book; public GameObject MovieBook; public GameObject Touroku; // Start is called before the first frame update void Start() { DaimahouGage = DaimahouGage.GetComponent<Image>(); Daimahoubool = false; } // Update is called once per frame void Update() { if (DaimahouGage.fillAmount >= 1) { Daimahoubool = true; } if(Daimahoubool == true) { Book.GetComponent<bookaction>().enabled = false; director.Play(); Touroku.SetActive(true); MovieBook.SetActive(true); DaimahouUI.SetActive(false); } } }
スクリプトを以下のように修正しました。
実行は一度だけになったのですが、DaimahouUIが非アクティブになってくれません。
ImageがDaimahouUIの中にあるからでしょうか?
この場合どうすればよいのか教えていただきたいです。
C#
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Playables; using UnityEngine.UI; public class DaimahouScript : MonoBehaviour { private bool Daimahoubool = false; public PlayableDirector director; public Image DaimahouGage; public GameObject DaimahouUI; public GameObject Book; public GameObject MovieBook; public GameObject Touroku; // Start is called before the first frame update void Start() { DaimahouGage = DaimahouGage.GetComponent<Image>(); } // Update is called once per frame void Update() { if (DaimahouGage.fillAmount == 1) { if (!Daimahoubool) { Daimahoubool = true; Book.GetComponent<bookaction>().enabled = false; director.Play(); Touroku.SetActive(true); MovieBook.SetActive(true); DaimahouUI.SetActive(false); } } } }
また、スクリプトを以下のように変更すると非アクティブ化はするのですが点滅しながら非アクティブになってしまいます。
C#
void Update() { if (DaimahouGage.fillAmount == 1) { DaimahouUI.SetActive(false); if (!Daimahoubool) { Daimahoubool = true; Book.GetComponent<bookaction>().enabled = false; director.Play(); Touroku.SetActive(true); MovieBook.SetActive(true); } } }
まだ回答がついていません
会員登録して回答してみよう