I got two foreaches each searching for objects with different tags.
foreach(GameObject o in GameObject.FindGameObjectsWithTag("QuestionBlock"))
{
//if this gameobject has a QuestionBlock component, we add it to the List
QuestionBlock qb = o.GetComponent<QuestionBlock>();
if(qb)
questionBlocks.Add(qb);
}
foreach(GameObject o in GameObject.FindGameObjectsWithTag("Question"))
{
//if this object has a question Component
Question q = o.GetComponent<Question>();
if(q)
{
questions.Add(q);
Debug.Log(q.question);
}
}
I have 5 QuestionBlocks in my scene and 5 Questions. The order in my hierarchy is: Question 1, QuestionBlock 1, Question 2, QuestionBlock 2, Question 3, Questionblock 3 etc etc.
When I start the game and look at the lists, the order of the Questionblocklist is: 5, 4, 1, 2, 3 and the order of the Questionlist is 5,4,1,3,2.
Here is a picture of the hierarchy and lists: http://i47.tinypic.com/2aoih4.png
Anyone know why this happens?
There is no order in these things. If you want and need order in your games you will have to make your list, have it ordered and call things trough it.