IEnumerator WaitForCreateChildre(float sec) { yield return(new WaitForSeconds(sec)); childrenList = new List <GameObject>(); people = new GameObject("People"); people.transform.SetParent(transform); var manager = spawnPointManager.GetComponent <SpawnpointManager>(); var boyPoints = manager.GetBoyPoints(); var boyIds = Utils.GetUniqueRandomInt(15, 0, 15); var teacherPoints = manager.GetTeacherPoints(); var girlPoints = manager.GetGirlPoints(); var neededKidsCounter = 0; neededBoyList = new List <int>(); var pointRandomizer = Utils.GetUniqueRandomInt(numChildren, 0, boyPoints.Length); for (int index = 0; index < numChildren; index++) { var boy = CreateGOAtPos(boyTemplate, boyPoints[pointRandomizer[index]]); boy.GetComponent <BoyController>().BoyID = boyIds[index]; boy.transform.SetParent(people.transform); if (neededKidsCounter < kidsNeeded) { neededBoyList.Add(boyIds[index]); string spriteString = "Sprites/Boys/boy_" + boyIds[index] + "/boy_down_idle"; Debug.Log("Trying to load sprite from " + spriteString); guiController.AddChildGUI(boyIds[index], Resources.Load <Sprite>(spriteString)); neededKidsCounter++; } childrenList.Add(boy); } pointRandomizer = Utils.GetUniqueRandomInt(teachersCount, 0, teacherPoints.Length); for (int index = 0; index < teachersCount; index++) { var teach = CreateGOAtPos(teacherTemplate, teacherPoints[pointRandomizer[index]]); teach.transform.SetParent(people.transform); } }