実装したいこと
Textを取得し、一定の値に到達したら、表示するようにしたい。
試したこと
text.gameObject.SetActive(true);
のように、して表示、非表示を行おうとしましたが、エラーを吐かれてできませんでした。
また、foreach文で子要素を取得できるというのを記事で確認したのでそれも試しましたが、実装できませんでした。もしかしたら、使い方を理解できていないのかもしれないですが・・・。
スクリプト
c#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5 6public class GameManager : MonoBehaviour { 7 8 public Text ComboText; 9 public int ComboCounter; 10 public float deltaTime; 11 12 public static float delta; 13 public static int Combo; 14 private Text text; 15 16 // Use this for initialization 17 void Start () { 18 //コンボ初期化 19 Combo = 0; 20 // ComboText.text = "Combo:0"; 21 } 22 23 // Update is called once per frame 24 void Update() 25 { 26 27 ComboCounter = Combo; 28 if(Combo == 0 || Combo <4) 29 { 30 foreach(Text text in transform) 31 { 32 text.gameObject.SetActive(false); 33 } 34 } 35 if (Combo > 5) 36 { 37 text.gameObject.SetActive(true); 38 ComboText.text = "Combo" + ComboCounter.ToString(); 39 } 40 //コンボ取得時に計測時間計測開始 41 if (Combo > 1) 42 { 43 //計測時間設定 44 delta += Time.deltaTime; 45 } 46 //計測時間を代入 47 deltaTime = delta; 48 49 if(deltaTime > 3) 50 { 51 //計測時間経過後コンボ初期化 52 Combo = 0; 53 Debug.Log("0"); 54 55 } 56 57 58 } 59} 60
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。