前提・実現したいこと
Unity2Dにて音ゲーを作っているんですが、変数に2次元配列の要素を代入しようとすると
IndexOutOfRangeException: Index was outside the bounds of the array.
Humen1.Jikkou1 () (at Assets/Humen1.cs:93)
Humen1+<Junbi>d__16.MoveNext () (at Assets/Humen1.cs:53)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at /Users/builduser/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17)
というエラーが出てしまいます。
どなたか教えていただけると幸いです。
発生している問題・エラーメッセージ
IndexOutOfRangeException: Index was outside the bounds of the array. Humen1.Jikkou1 () (at Assets/Humen1.cs:93) Humen1+<Junbi>d__16.MoveNext () (at Assets/Humen1.cs:53) UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at /Users/builduser/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17)
該当のソースコード
C#
1//93/53行目 2using System.Collections; 3using System.Collections.Generic; 4using UnityEngine; 5using System; 6 7public class Humen1 : MonoBehaviour 8{ 9 public GameObject Notes; 10 public GameObject Notes2; 11 public GameObject Notes3; 12 public GameObject Notes4; 13 public GameObject Notes5; 14 public GameObject Notes6; 15 public GameObject Notes7; 16 public GameObject Notes8; 17 public GameObject Notes9; 18 public GameObject Notes10; 19 public int z = 0; 20 int x = 0; 21 /* 22 float a; 23 float b; 24 float c; 25 float d; 26 float e; 27 float a1; 28 float b1; 29 float c1; 30 float d1; 31 float e1; 32 */ 33 // Start is called before the first frame update 34 35 void Start() 36 { 37 StartCoroutine(Wait(1f)); 38 StartCoroutine(Junbi()); 39 FadeManager.FadeIn(); 40 } 41 42 // Update is called once per frame 43 public int Jikkou 44 { 45 // 取得 46 get { return z; } 47 48 // 変更 49 set { z = value; } 50 } 51 public IEnumerator Junbi() 52 { 53 yield return new WaitUntil(Z); 54 Jikkou1(); 55 } 56 public void Jikkou1() 57 { 58 int a; 59 int b; 60 int c; 61 float d; 62 float e; 63 float[,] notes1; 64 notes1 = new float[22,5] { 65 {4,2,2,-7.4f,6}, 66 {4,3,2,3.7f,-6}, 67 {5,0,2,7.4f,6}, 68 {5,1,2,-3.7f,-6}, 69 {5,2,2,0,-6}, 70 {5,3,0,-3.7f,6}, 71 {5,3,0,3.7f,6}, 72 {5,3,2,0,-6}, 73 {6,0,2,3.7f,-6}, 74 {6,0,2,-3.7f,-6}, 75 {6,1,0,0,6}, 76 {6,1,2,3.7f,-6}, 77 {6,1,2,-3.7f,-6}, 78 {6,2,2,0,-6}, 79 {6,3,0,-7.4f,6}, 80 {6,3,0,7.4f,6}, 81 {6,3,2,0,-6}, 82 {7,0,2,7.4f,-6}, 83 {7,0,2,-7.4f,-6}, 84 {7,1,0,0,6}, 85 {7,1,2,7.4f,-6}, 86 {7,1,2,-7.4f,-6}, 87 88 89 //{, , , , } 90 }; 91 //int y = notes1.Length; 92 for (int i = 0; i < notes1.Length; ++i) 93 { 94 a = (int)notes1[i,x]; 95 ++x; 96 b = (int)notes1[i, x]; 97 ++x; 98 c = (int)notes1[i, x]; 99 ++x; 100 d = notes1[i, x]; 101 ++x; 102 e = notes1[i, x]; 103 x = 0; 104 105 if (Mathf.Approximately(e, 6.0f)) 106 { 107 switch (d) 108 { 109 case -7.4f: 110 GameObject notes = Instantiate(Notes, new Vector3(d, 6.0f, 0.0f), Quaternion.identity) as GameObject; 111 NotesIdou a_1 = notes.GetComponent<NotesIdou>(); 112 a_1.Idou(a, b, c); 113 break; 114 case -3.7f: 115 GameObject notes2 = Instantiate(Notes2, new Vector3(d, 6.0f, 0.0f), Quaternion.identity) as GameObject; 116 NotesIdou2 a_2 = notes2.GetComponent<NotesIdou2>(); 117 a_2.Idou(a, b, c); 118 break; 119 case 0: 120 GameObject notes3 = Instantiate(Notes3, new Vector3(d, 6.0f, 0.0f), Quaternion.identity) as GameObject; 121 NotesIdou3 a_3 = notes3.GetComponent<NotesIdou3>(); 122 a_3.Idou(a, b, c); 123 break; 124 case 3.7f: 125 GameObject notes4 = Instantiate(Notes4, new Vector3(d, 6.0f, 0.0f), Quaternion.identity) as GameObject; 126 NotesIdou4 a_4 = notes4.GetComponent<NotesIdou4>(); 127 a_4.Idou(a, b, c); 128 break; 129 case 7.4f: 130 GameObject notes5 = Instantiate(Notes5, new Vector3(d, 6.0f, 0.0f), Quaternion.identity) as GameObject; 131 NotesIdou5 a_5 = notes5.GetComponent<NotesIdou5>(); 132 a_5.Idou(a, b, c); 133 break; 134 } 135 }else{ 136 //if (Mathf.Approximately(e, -6.0f) 137 switch (d) 138 { 139 case -7.4f: 140 GameObject notes6 = Instantiate(Notes6, new Vector3(d, -6.0f, 0.0f), Quaternion.identity) as GameObject; 141 NotesIdou6 a_6 = notes6.GetComponent<NotesIdou6>(); 142 a_6.Idou(a, b, c); 143 break; 144 case -3.7f: 145 GameObject notes7 = Instantiate(Notes7, new Vector3(d, -6.0f, 0.0f), Quaternion.identity) as GameObject; 146 NotesIdou7 a_7 = notes7.GetComponent<NotesIdou7>(); 147 a_7.Idou(a, b, c); 148 break; 149 case 0: 150 GameObject notes8 = Instantiate(Notes8, new Vector3(d, -6.0f, 0.0f), Quaternion.identity) as GameObject; 151 NotesIdou8 a_8 = notes8.GetComponent<NotesIdou8>(); 152 a_8.Idou(a, b, c); 153 break; 154 case 3.7f: 155 GameObject notes9 = Instantiate(Notes9, new Vector3(d, -6.0f, 0.0f), Quaternion.identity) as GameObject; 156 NotesIdou9 a_9 = notes9.GetComponent<NotesIdou9>(); 157 a_9.Idou(a, b, c); 158 break; 159 case 7.4f: 160 GameObject notes10 = Instantiate(Notes10, new Vector3(d, -6.0f, 0.0f), Quaternion.identity) as GameObject; 161 NotesIdou10 a_10 = notes10.GetComponent<NotesIdou10>(); 162 a_10.Idou(a, b, c); 163 break; 164 } 165 } 166 167 168 } 169 } 170 private bool Z() => z == 1; 171 IEnumerator Wait(float wait) 172 { 173 yield return new WaitForSeconds(wait); 174 } 175 176} 177 178 179
補足情報(FW/ツールのバージョンなど)
Unity
2019.2.5f1
回答1件
あなたの回答
tips
プレビュー