Before updating to Windows 10 you may need to return your Pro license. More information here

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?

more ▼

asked Aug 23, 2011 at 02:02 AM

avatar image

1 32 25 27

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

@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

more ▼

answered Aug 23, 2011 at 07:33 AM

avatar image

815 105 94 108

Thank you, I was using a Random.range for the Vector3 but this will work a lot better thanks!

Aug 23, 2011 at 07:08 PM SYNYST3R1
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Aug 23, 2011 at 02:02 AM

Seen: 1411 times

Last Updated: Aug 23, 2011 at 07:08 PM