- Home /
Question by
SYNYST3R1 · Aug 23, 2011 at 02:02 AM ·
gameobjectinstantiateotherinsideeach
How do you stop GameObjects from instantiating inside itself?
I have a foreach loop that instantiates a tile in a random range Vector3. When I instantiate the object it is inside the other ones and it flickers and causes massive lag. How do I make it not instantiate the object there again if its already there?
Comment
Best Answer
Answer by sriram90 · Aug 23, 2011 at 07:33 AM
@SYNYST3R1 : hey its very simple to make don't get tense.
just changing the position of instantiated objects in vector3.
here is sample :
var prefab : Transform;
for (var i : int = 0;i < 10; i++) {
Instantiate (prefab, Vector3(i * 2.0, 0, 0), Quaternion.identity);
}
it'll instantiate every object 2 units apart from x axis.
Refer this: http://unity3d.com/support/documentation/ScriptReference/Object.Instantiate.html
Thank you, I was using a Random.range for the Vector3 but this will work a lot better thanks!
Your answer
![](https://koobas.hobune.stream/wayback/20220612190406im_/https://answers.unity.com/themes/thub/images/avi.jpg)