Home > Net >  How to Instantiate a Gameobject as a child in a Queue
How to Instantiate a Gameobject as a child in a Queue

Time:12-01

How to instantiate a gameobject in a Queue as a child of a gameobject in unity
Thanks

  void SpawnSolders()
    {
        for (int i = 0; i < warriorsCount; i  )
        {
            if (isOcupied[i] == false)
            {
                isOcupied[i] = true;
                warriorsQ.Enqueue((GameObject)Instantiate(war1, battlePositions[i].position, transform.rotation));
            }
        }
    }

CodePudding user response:

You need to pass parent parameter to Instantiate function.

void SpawnSolders()
{
    for (int i = 0; i < warriorsCount; i  )
    {
        if (isOcupied[i] == false)
        {
            isOcupied[i] = true;
            warriorsQ.Enqueue((GameObject)Instantiate(war1, battlePositions[i].position, transform.rotation, parentGameObject.transform));
        }
    }
}
  • Related