Buttonを押したら17秒後に違うButtonが表示されるようにしたいのですがうまくいきません。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5 6// ボタン表示、非表示スクリプト 7public class TransparentCanvas : MonoBehaviour 8{ 9 // 親オブジェクト指定 10 static Canvas _canvas; 11 void Start() 12 { 13 // Canvasコンポーネントを保持 14 _canvas = GetComponent<Canvas>(); 15 } 16 17 public static void SetActive(string name, bool b) 18 { 19 foreach (Transform child in _canvas.transform) 20 { 21 // 子の要素をたどる 22 if (child.name == name) 23 { 24 // 指定した名前と一致したら表示 25 child.gameObject.SetActive(b); 26 27 // 終了 28 return; 29 } 30 } 31 } 32} 33
上記のCanvas内buttonを条件が一致したら表示するというScriptを使用しており、以下のScriptを書いてみたのですがエラーが起きました。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5 6 7public class TransparenMainButtonCall : MonoBehaviour 8{ 9 public GameObject objectA; 10 public GameObject objectB; 11 public GameObject objectC; 12 13 void Start() 14 { 15 StartCoroutine("MainButtonPus"); 16 objectA;.gameObject.SetActive(false); 17 objectB;.gameObject.SetActive(false); 18 objectC;.SetActive(false); 19 } 20 21 // ボタンをクリックした時の処理 22 public void OnClick() 23 { 24 // ボタンを非表示にする 25 gameObject.SetActive(false); 26 } 27 28 IEnumerable MainButtonPush() 29 { 30 31 // ボタンを表示する 32 yield return new WaitForSeconds(17f); 33 TransparentCanvas.SetActive("objectA;", true); 34 35 yield return new WaitForSeconds(17f); 36 TransparentCanvas.SetActive("objectB;", true); 37 38 yield return new WaitForSeconds(17f); 39 TransparentCanvas.SetActive("objectC;", true); 40 } 41 42} 43 44
以下エラー文
Coroutine 'MainButtonPus' couldn't be started!
UnityEngine.MonoBehaviour:StartCoroutine(String)
TransparenMainButtonCall:Start() (at Assets/Scripts/SceneConclusionScripts/TransparenMainButtonCall.cs:15)
何でつまずいているのか見当がつかずにいます。
解決方法のご教授おねがいします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/10 08:58