IndexOutOfRangeException: Array-Index liegt außerhalb des Bereichs. WordScramble.ShowScramble (Int32 index, Int32 index2) (bei Assets/Wort Sramble/WordScramble.cs: 210) WordScramble.Start() (bei Assets/Wort Sramble/WordScramble.cs: 134)IndexOutOfRangeException: Array-Index liegt außerhalb des Bereichs.
public void ShowScramble(int index, int index2)
{
textObjects.Clear();
charObjects.Clear();
foreach (Transform child in container)
{
Destroy (child.gameObject);
}
//WORDS FINISHED
//SHOW RESULT SCREEN
if ((index > words.Length - 1) && (index2 > questions.Length - 1))
{
result.ShowResult();
wordCanvas.SetActive(false);
//Debug.Log ("index out of range, please enter range between 0-" + (words.Length - 1).ToString());
return;
}
char[] chars = words [index].GetString().ToCharArray();
char[] chars2 = questions [index2].GetString().ToCharArray();
foreach (char c in chars)
{
TextObject clone2 = Instantiate (prefabQstn.gameObject).GetComponent<TextObject>();
CharObject clone = Instantiate (prefab.gameObject).GetComponent<CharObject>();
clone.transform.SetParent (container);
clone2.transform.SetParent (containerQstn);
textObjects.Add (clone2.Init (c));
charObjects.Add (clone.Init (c));
}
currentQstn = index2;
currentWord = index;
StartCoroutine (TimeLimit());
}
Bitte erklären Sie das Problem, anstatt die Code-/Exception-Meldung – Sybren
dumping Die Bedingung '(index> words.Length - 1) && (index2> questions.Length - 1)' ist nur wahr, wenn ** beide Indizes ** sind größer als ihre jeweiligen Längen so offensichtlich können Sie einen ungültigen Index an Arrays übergeben. –