Unity2Dでゲーム開発をしております。IEnumeratorを使って処理を中断、ボタンが押されたら再開、という風にしたいと思います。
以下がコードです。
CoroutineTest
1 2public class TutorialADirectorScript : MonoBehaviour 3{ 4 private int frameCount; 5 6 // Use this for initialization 7 private void Start() 8 { 9 StartCoroutine(MainCoroutine()); 10 } 11 12 // Update is called once per frame 13 private void Update() 14 { 15 // フレーム数を取得 16 frameCount++; 17 } 18 19 // MainCoroutine 20 private IEnumerator MainCoroutine() 21 { 22 // サブコルーチンの終了まで待機 23 yield return SubCoroutine(); 24 Debug.Log("Frame: " + frameCount); 25 26 // カスタムコルーチンの終了まで待機 27 yield return new CustomYieldInstructionTest(); 28 Debug.Log("Finished !!"); 29 } 30 31 // SubCoroutine 32 private IEnumerator SubCoroutine() 33 { 34 while (frameCount < 150) 35 { 36 yield return null; 37 } 38 } 39} 40
CustomYieldInstructionTest
1 2public class CustomYieldInstructionTest : CustomYieldInstruction 3{ 4 // keepWaitingがtrueを返す間は処理が中断される 5 public override bool keepWaiting 6 { 7 get 8 { 9 // Enterキーの入力状態がfalseの間はtrueを返す 10 // return !Input.GetKeyDown(KeyCode.Return); 11 12 // ***上のInput.GetKeyDownのように 13 // ***ここで"UPButton"が押されたらfalseを返して再開させたい 14 Button button = GameObject.Find("UPButton").GetComponent<Button>(); 15 return button.OnPointerDown(); 16 } 17 } 18 19 // Constructor 20 public CustomYieldInstructionTest() 21 { 22 Debug.Log("Please press the Enterkey"); 23 } 24}
●やりたいこと
CustomYieldInstructionTest内で return !Input.GetKeyDown(KeyCode.Return);で再開するように、"UPButton"が押されたら再開するようにしたい。
OnPointerDownが押された時にTrueが返ってくればいける気がするのですがやり方がわかりません。どなたかご教授をお願いいたします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。