Question by
colourcrisis · Dec 23, 2018 at 10:34 PM ·
c#gameobjectinstantiatetag
Instantiate as child for gameobjects with tag
I want to instantiate a prefab as a child gameobject for all gameobjects that have a certain tag.
I tried this but not working.
GameObject[] gameObjs;
public GameObject prefab;
GameObject clone;
private void Start()
{
gameObjs = GameObject.FindGameObjectsWithTag("symbol");
foreach (GameObject go in gameObjs)
{
clone = Instantiate(blue, go.transform.position, Quaternion.identity) as GameObject;
clone.transform.parent = go.transform;
clone.transform.Translate(0, -150, 0, Space.World);
}
}
Comment
Answer by Frostbite23 · Dec 24, 2018 at 03:01 AM
try
GameObject[] gameObjs;
public GameObject prefab;
private void Start()
{
gameObjs = GameObject.FindGameObjectsWithTag("symbol");
foreach (GameObject go in gameObjs)
{
GameObject clone = Instantiate(blue, go.transform.position, Quaternion.identity) as GameObject;
clone.transform.SetParent(go.transform);
clone.transform.Translate(0, -150, 0, Space.World);
}
}