if文とGetComponentを使用し、Aのボタンが押されたら指定の秒数後にObjectが現れ、その指定の秒数に満たない時間でBボタンを押したらAのボタンの処理(指定時間後にObjectを表示)を停止するというものを作成したのですが、指定時間に満たない時間でBボタンを押しても、処理が停止せずに指定の時間が経過したらObjectが表示されてしまいます。
下記サイト等参考にさせて頂いたのですが上記のような状態になってしまいます。
参考サイト
参考サイト
呼び出そうとしているScript(Bボタン)に複数Scriptがついているのですが、これも原因の一つでしょうか。
何卒ご教示のほどよろしくお願いいたします。
AボタンについているScriptです。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class AButtonInvoke : MonoBehaviour 6{ 7 // オブジェクト指定 8 public GameObject AButtonControl; 9 10 public GameObject MainObject; 11 12 public GameObject AButton; 13 14 public GameObject BButton; 15 16 17 // ボタンをクリックした時の処理 18 public void OnClick() 19 { 20 StartCoroutine("AbuttonPush"); 21 } 22// 現れる時間指定 23 IEnumerator AbuttonPush() 24 { 25 // 現れる時間 26 yield return new WaitForSeconds(13f); 27 28 if (Interruption_Controller.GetComponent<Interruption>()) yield break; 29 { 30 Debug.Log("停止した"); 31 } 32 yield return new WaitForSeconds(13f); 33 MainObject.gameObject.SetActive(true);
Bボタンに付けているScriptです。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5 6public class BButtonControl : MonoBehaviour 7{ 8 9 // ボタンをクリックした時の処理 10 public void OnClick() 11 { 12 // ボタンを非表示にする 13 gameObject.SetActive(false); 14 TransparentCanvas.SetActive("MainObject", true); 15 16 // ボタンを表示する 17 TransparentCanvas.SetActive("AButton", true); 18 } 19}
InterruptionScriptです。
C# using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Interruption : MonoBehaviour { // オブジェクト指定 public GameObject AButtonControl; public GameObject MainObject; public GameObject AButton; public GameObject BButton; // オブジェクト非表示 void Start() { MainObject.gameObject.SetActive(false); } // ボタンをクリックした時の処理 public void OnClick() { paused = true; StartCoroutine("startPush"); gameObject.SetActive(false); } // 現れる時間指定 IEnumerator startPush() { yield return new WaitForSeconds(1f); MainMenu_Scene.gameObject.SetActive(true); // Objectを表示する IEnumerator startPush() { yield return new WaitForSeconds(1f); MainObject.gameObject.SetActive(true); yield return new WaitForSeconds(1f); TransparentCanvas.SetActive("AButton", true); } } ``` 上記が付けている物になります。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。