ButtonAを押したらGameObjectが時間差で現れるという動きをしたいのですが、うまくいきません。
以下のScriptを記入したのですが、ここからどうButtonAをクリックしたら時間差で現れるようになるでしょうか。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class UseCasesTimeLagControl : MonoBehaviour { 6 7 public GameObject CubeA; 8 public GameObject CubeB; 9 public GameObject CubeC; 10 public GameObject CubeD; 11 public GameObject CubeE; 12 13 14 15 void Start() 16 { 17 StartCoroutine("UseCasesTimeLag"); 18 CubeA.gameObject.SetActive(false); 19 20 StartCoroutine("UseCasesTimeLag"); 21 CubeB.gameObject.SetActive(false); 22 23 StartCoroutine("UseCasesTimeLag"); 24 CubeC.gameObject.SetActive(false); 25 26 StartCoroutine("UseCasesTimeLag"); 27 CubeD.gameObject.SetActive(false); 28 29 StartCoroutine("UseCasesTimeLag"); 30 CubeE.gameObject.SetActive(false); 31 } 32 33 IEnumerator UseCasesTimeLag() 34 { 35 CubeA.gameObject.SetActive(false); 36 yield return new WaitForSeconds(1.0f); 37 CubeA.gameObject.SetActive(true); 38 39 CubeB.gameObject.SetActive(false); 40 yield return new WaitForSeconds(2.0f); 41 CubeB.gameObject.SetActive(true); 42 43 CubeC.gameObject.SetActive(false); 44 yield return new WaitForSeconds(3.0f); 45 CubeC.gameObject.SetActive(true); 46 47 CubeD.gameObject.SetActive(false); 48 yield return new WaitForSeconds(4.0f); 49 CubeD.gameObject.SetActive(true); 50 51 CubeE.gameObject.SetActive(false); 52 yield return new WaitForSeconds(5.0f); 53 CubeE.gameObject.SetActive(true); 54 55 } 56} 57
解決方法のご教授おねがいします。
失礼しました。
「Unityにて一定の時間経過後にButtonを表示させる」にて質問させていただいた際のご回答にてエラーは消えたのですが、Buttonを押していないにもかかわらず指定した時間がたつとButtonが現れるという事に気づきまして再度ご教示頂きたく上げさせていただきました。
新規ではなく、前回の場所で上げるべきでした。
以下追加文
C#
1public void OnClick() 2 { 3 // ボタンを非表示にする 4 gameObject.SetActive(false); 5 } 6を上記に記載したScriptに記入し、ButtonAを押したら非表示にするは出来たのですが、時間差指定したobjectはButtonAのアクションに関係なく時間がたてば現れてしまいまして。 7この文になにが足らないのかが分からなく。 8
回答2件
あなたの回答
tips
プレビュー