前提・実現したいこと
unityでターン制バトルを行うシステムを作っています。
coroutineでEnterを押すまで処理が止まる機能が所々実装できません
発生している問題・エラーメッセージ
coroutineが動かない場所がある。
該当のソースコード
c#
1 Message.text = "敵のターンだ!"; 2 yield return new WaitUntil(() => Input.GetButtonDown("Submit")); 3 /*Message.text=*/Debug.Log( list[turn].name + "の攻撃!"); 4 5 yield return new WaitUntil(() => Input.GetButtonDown("Submit"));// <=起きない 6 audioSource.PlayOneShot(sound[1]); 7 PLstatus.hp = PLstatus.hp - list[turn].attack; 8 if (PLstatus.hp <= 0) 9 { 10 PLstatus.hp = 0; 11 } 12 HPchange(); 13 Debug.Log("ターン" + turn); 14 Debug.Log(list[turn].name); 15 Message.text = PLstatus.Playername + "は" + list[turn].attack + "のダメージを受けた!"; 16 yield return new WaitUntil(() => Input.GetButtonDown("Submit")); 17 IsRunning = false; 18 turn2 = true; 19 Debug.Log("敵オワタン"); 20 Debug.Log("turn2" + turn2); 21 turnjudge();
c#
1IEnumerator PlayerAttackTurn() 2 { 3 Debug.Log(IsRunning); 4 if (IsRunning) 5 { 6 yield break; 7 } 8 IsRunning = true; 9 Message.text = PLstatus.Playername + "のターン"; 10 Debug.Log("ターン" + turn); 11 Debug.Log(list[turn].name); 12 yield return new WaitUntil(() => Input.GetButtonDown("Submit")); 13 Message.text = "行動を選択せよ"; 14 yield return new WaitUntil(() => Input.GetButtonDown("Submit")); 15 At.interactable = true; 16 At.alpha = 1.0f; 17 yield return new WaitUntil(() => trigger.Judge == true | trigger.Judge2 == true); 18 if(trigger.Judge == true | trigger.Judge2 == true) 19 { 20 switch (trigger.number) 21 { 22 case 1: 23 AllMenue.interactable = false; 24 AllMenue.alpha = 0; 25 At.interactable = false; 26 EventSystem.current.SetSelectedGameObject(AttackButton); 27 Monster[trigger.SelectMonster].hp = Monster[trigger.SelectMonster].hp - skill.skill[0].value; 28 Message.text = Monster[trigger.SelectMonster].name + "に" + skill.skill[0].value + "与えた!"; 29 yield return new WaitUntil(() => Input.GetButtonDown("Submit"));// <=ここが起きない 30 IsPlayerTurn = false; 31 IsRunning = false; 32 turn2 = true; 33 trigger.Judge = false; 34 trigger.Judge2 = false; 35 turnjudge(); 36 break; 37 case 2: 38 AllMenue.interactable = false; 39 AllMenue.alpha = 0; 40 At.interactable = false; 41 EventSystem.current.SetSelectedGameObject(AttackButton); 42 Monster[trigger.SelectMonster].hp = Monster[trigger.SelectMonster].hp - skill.skill[1].value; 43 Message.text = Monster[trigger.SelectMonster].name + "に" + skill.skill[1].value + "与えた!";// <=ここが起きない 44 IsPlayerTurn = false; 45 IsRunning = false; 46 turn2 = true; 47 trigger.Judge = false; 48 trigger.Judge2 = false; 49 turnjudge(); 50 yield return new WaitUntil(() => Input.GetButtonDown("Submit")); 51 break; 52 case 3: 53 AllMenue.interactable = false; 54 AllMenue.alpha = 0; 55 At.interactable = false; 56 EventSystem.current.SetSelectedGameObject(AttackButton); 57 Monster[trigger.SelectMonster].hp = Monster[trigger.SelectMonster].hp - skill.skill[2].value; 58 Message.text = Monster[trigger.SelectMonster].name + "に" + skill.skill[2].value + "与えた!"; 59 IsPlayerTurn = false; 60 IsRunning = false; 61 turn2 = true; 62 trigger.Judge = false; 63 trigger.Judge2 = false; 64 turnjudge(); 65 yield return new WaitUntil(() => Input.GetButtonDown("Submit"));// <=ここが起きない 66 break; 67 } 68 69 }
c#
1public void system() 2 { 3 if (!finish) return; 4 if (list[turn].judgePL == true) 5 { 6 IsPlayerTurn = true; 7 } 8 else 9 { 10 IsPlayerTurn = false; 11 } 12 if (!IsPlayerTurn) 13 { 14 Debug.Log("敵"); 15 finish = false; 16 StartCoroutine(Enemy()); 17 } 18 else if (IsPlayerTurn) 19 { 20 Debug.Log("味方"); 21 finish = false; 22 StartCoroutine(PlayerAttackTurn()); 23 } 24 }
補足情報(FW/ツールのバージョンなど)
スクリプト内の起きない場所にマークしました。
trigger.numberの引数
c#
1 public void Skill1() 2 { 3 number = 1; 4 } 5 public void Skill2() 6 { 7 number = 2; 8 } 9 public void Skill3() 10 { 11 number = 3; 12 } 13 public void MonsterSel1() 14 { 15 Judge = true; 16 SelectMonster = 0; 17 } 18 public void MonsterSel2() 19 { 20 Judge2 = true; 21 SelectMonster = 1; 22 }
初心者なゆえ汚いプログラムお許しください。
回答1件
あなたの回答
tips
プレビュー