- Home /
Instantiate Game Object on Array of Transforms
I am trying to Instantiate a Game Object on the next available Array of Transforms. What is happening with my current code is each of the 5 game object models are being instantiated on each of the 5 transforms. Meaning I have 5 models stacked on every one of the transforms for a total of 25 models when I want one model on each of the 5 transforms for a total of 5 models.
I want it to look like whats on the right. One model per one transform.
The left is an example of what is happening on each of the 5 transforms.
public Transform[] transforms2; //array of five transforms
GameObject CreateACardAtPosition(CardAsset c, Vector3 position, Vector3 eulerAngles) { if (c.TypeOfCard == TypesOfCards.Creature) { for (var i = 0; i < transforms2.Length; i++)//test { GameObject clone = GameObject.Instantiate(c.Graphic3D, transforms2[i].transform.position, Quaternion.identity);//Game Object clone is equal to instantiated game object from model Graphic3D, with transform of i } } }
Any help would be greatly appreciated
Answer by khjunxxllc · Aug 19, 2018 at 05:27 PM
I am not sure why the code posted like that
public Transform[] transforms2; //array of five transforms
GameObject CreateACardAtPosition(CardAsset c, Vector3 position, Vector3 eulerAngles)
{
if (c.TypeOfCard == TypesOfCards.Creature)
{
for (var i = 0; i < transforms2.Length; i++)//test
{
GameObject clone = GameObject.Instantiate(c.Graphic3D, transforms2[i].transform.position, Quaternion.identity);//Game Object clone is equal to instantiated game object from model Graphic3D, with transform of i
}
}
}
Any help would be greatly appreciated