So I’m working on a game where I want to randomly spawn different arrangements of blocks as obstacles.
I created an empty gameobject as a parent and put the blocks around it as children so I adjust the position properly. Afterwards I created a prefab of this and loaded it into an array so I can randomly choose one in the future. But if I now want to spawn the prefab with a custom position it not only spawns there but also on the position the prefab itself has assigned to. Is there a way to prevent this?
My code:
void Start()
{
prefab[0] = GameObject.Instantiate(Resources.Load("prefab1")) as GameObject;
// Instantiate at position (0, 0, 0) and zero rotation.
Instantiate(prefab[0], new Vector3(0, 1, 140), Quaternion.identity);
Instantiate(prefab[0], new Vector3(0, 1, 120), Quaternion.identity);
}
Interestingly I can initiate two objects of the same type but the bug only occurs once.