Question by
franklin22 · Mar 16, 2017 at 02:45 PM ·
index
IndexOutOfRangeException: Array index is out of range. GameManager.initializeCards () (at Assets/Scripts/GameManager.cs:41) GameManager.Update () (at Assets/Scripts/GameManager.cs:23)
if (!_init)
initializeCards ();
if (Input.GetMouseButtonUp (0))
checkCards ();
}
void initializeCards()
{
for (int id = 0; id < 2; id++)
{
for (int i = 1; i < 14; i++)
{
bool test = false;
int choice = 0;
while (!test)
{
choice = Random.Range (0, cards.Length);
test = !(cards [choice].GetComponent<Card> ().initialized);
}
cards [choice].GetComponent<Card> ().cardValue = i;
cards [choice].GetComponent<Card> ().initialized = true;
}
}
foreach (GameObject c in cards)
c.GetComponent<Card> ().setupGraphics ();
if (!_init)
_init = true;
Comment
You haven't pasted the entire script, nor have you given any sort of context. Can you give any more information?
I suspect that your cards array hasn't been properly initialized, but there's no way of knowing without seeing your whole script
Your answer
Follow this Question
Related Questions
What is wrong with my c# script? The error os ArgumentException(For Android) 2 Answers
How can i make a door-key script to a multiple keys and doors? 0 Answers
accesing multiple objects that share the same script from another script 0 Answers
Insert object to the list in the script in real-time. 1 Answer