- Home /
How to make multiple gameobjects child of one and the same transform (SCRIPT)
So I made a building system in my game and all the blocks I can place are tagged with the tag "Block". So and now I want that every placed block should be a child of the same transform. So I mean when I place 10 blocks all 10 blocks should have the same parent. I hope you can help me !
Comment
https://docs.unity3d.com/ScriptReference/Transform-parent.html have a look at this
thanks bro, but I doesn't understand the script :/ it always makes errors
hm ok this should work
public Transform[] m_Block;
public Transform m_Parent;
void Start(){
foreach (Transform trans in m_Block){
trans.parent = m_Parent;}
}
Best Answer
Answer by hameed-ullah-jan · Jul 05, 2018 at 05:59 PM
HI, there try this code, i wrote it for you and it's working fine.
public GameObject[] AllObjects;
public GameObject ParentObj;
// Use this for initialization
void Start () {
AllObjects = GameObject.FindGameObjectsWithTag ("Bomb");
foreach(GameObject obj in AllObjects){
obj.transform.SetParent (ParentObj.transform);
}
}