参考サイト:TokamakRocket 格ゲー風コマンド入力
http://tkmkrocket.net/doc/?p=88
http://tkmkrocket.net/doc/?p=95
サイトを参考にコマンド入力を確認するプログラムを組んでみたのですが以下のようなエラー文が表示されました。
「Assets/charControl.cs(12,14): error CS1624: The body of charControl.Start() cannot be an iterator block because `void' is not an iterator interface type」
イテレータの中にはvoid型は使えない、というエラー文だと思うのですが...どう解決すればいいのかわかりませんでした...
ご存知の方がいらっしゃいましたらご教授いただけましたら幸いです。
どうぞよろしくお願いいたします。
以下、作成したプログラムになります。
C#
1using UnityEngine; 2using System.Collections; 3using System.Text.RegularExpressions; 4 5public class charControl : MonoBehaviour { 6 7 string inputCommands = ""; 8 bool commandEnable = true; 9 int recCommandLength = 100; 10 11 // Use this for initialization 12 void Start () { 13 inputCommands = inputCommands.PadLeft(100); 14 StartCoroutine("confirmCommand"); 15 while (true){ 16 //command 17 if(commandEnable){ 18 getAxis(); 19 getFire(); 20 }else{ 21 inputCommands += " "; 22 } 23 yield return null; 24 }//end While 25 } 26 27 // Update is called once per frame 28 void Update () { 29 } 30 31 32 void getAxis(){ 33 if(Input.GetAxisRaw("Vertical") > 0.9){ 34 if(Input.GetAxisRaw("Horizontal") > 0.9){inputCommands += "9";} 35 else if (Input.GetAxisRaw("Horizontal") < -0.9){inputCommands += "7";} 36 else if (Input.GetAxisRaw("Horizontal") == 0){inputCommands += "8";} 37 else {inputCommands += "8";} 38 } 39 40 else if(Input.GetAxisRaw("Vertical") < -0.9){ 41 if(Input.GetAxisRaw("Horizontal") > 0.9){inputCommands += "3";} 42 else if(Input.GetAxisRaw("Horizontal") < -0.9){inputCommands += "1";} 43 else if(Input.GetAxisRaw("Horizontal") == 0){inputCommands += "2";} 44 else {} 45 } 46 else if(Input.GetAxisRaw("Vertical") == 0){ 47 48 if(Input.GetAxisRaw("Horizontal") > 0.9){inputCommands += "6";} 49 else if(Input.GetAxisRaw("Horizontal") < -0.9){inputCommands += "4";} 50 else if(Input.GetAxisRaw("Horizontal") == 0){inputCommands += "5";} 51 else {} 52 }else{ 53 54 } 55 56 if(inputCommands.Length > recCommandLength){ 57 inputCommands = inputCommands.Remove(0,1); 58 } 59 60 } 61 62 void getFire(){ 63 //fire 64 if(Input.GetButton("Fire1") == true){ 65 inputCommands += "f"; 66 } 67 68 if(inputCommands.Length > recCommandLength){ 69 inputCommands = inputCommands.Remove(0,1); 70 } 71 } 72 73 private IEnumerator confirmCommand(){ 74 while (true) { 75 int comLength = 0; 76 string checkframe = " "; 77 78 string testB = "6[0-9]*5[0-9]*2[0-9]*6[0-9]*f"; 79 comLength = 30; 80 checkframe = inputCommands.Remove (0, recCommandLength - comLength); 81 if (Regex.IsMatch (checkframe, testB)) { 82 Debug.Log ("SHORYUKEN!"); 83 yield return new WaitForSeconds (1.5f); 84 } 85 86 string testA = "2[0-9]*6[0-9]*[f]"; 87 comLength = 30; 88 checkframe = inputCommands.Remove (0, recCommandLength - comLength); 89 if (Regex.IsMatch (checkframe, testA)) { 90 Debug.Log("HADOUKEN!"); 91 yield return new WaitForSeconds (1.0f); 92 } 93 94 string testC = "f"; 95 comLength = 1; 96 checkframe = inputCommands.Remove (0, recCommandLength - comLength); 97 if (Regex.IsMatch (checkframe, testC)) { 98 Debug.Log("KOUGEKI!"); 99 yield return new WaitForSeconds (0.1f); 100 } 101 yield return null; 102 } 103 } 104}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/10/04 16:05