hi there ![]()
i created this Script to build a prefab (inlcuding 32x32 blocks as children):
IEnumerator createMap() {
int maprun_x = 0;
int maprun_y = 0;
float pos_x = 0;
float pos_y = 0;
int blockid = 0;
GameObject[] created_block;
created_block = new GameObject[101];
for(maprun_x=0; maprun_x<101; maprun_x++){
created_block[maprun_x] = null;
}
Debug.LogError(mapsize_x+" | "+mapsize_y);
for(maprun_y=0; maprun_y<mapsize_y; maprun_y++){
for(maprun_x=0; maprun_x<mapsize_x; maprun_x++){
pos_x = maprun_x*size.x;
pos_y = maprun_y*size.z;
created_block[blockid] = Instantiate(BasicMapPrefab, new Vector3(pos_x, 0, pos_y), Quaternion.identity) as GameObject;
created_block[blockid].transform.parent = selfObject.transform;
created_block[blockid].name = "DirtBlock_"+(maprun_x+1)+"/"+(maprun_y+1);
Debug.Log(created_block[blockid].name+" created!");
blockid ++;
}
//wait after every row / update percentage of UI Loadbar
yield return 0;
}
//Detach children and add them to the Block_Holder
for(maprun_x=0; maprun_x<101; maprun_x++){
if(created_block[maprun_x] != null){
foreach(Transform child in created_block[maprun_x].transform){
child.parent = selfObject.transform;
}
yield return 0;
created_block[maprun_x].transform.DetachChildren();
Destroy(created_block[maprun_x]);
}
}
}
In the lower half of this code, i want to run through all of a Prefabs children, and re-parent them to a new object in the scene (and delete the prefab then).
Thsi works… half the way… Cause only the half of the childrens are re-parented correctly - the others are just shown free in the hierarchy ._.
What have i done wrong?