x


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

SYNYST3R1 gravatar image

SYNYST3R1
1 32 24 26

(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

sriram90 gravatar image

sriram90
805 100 87 102

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

By RSS:

Answers

Answers and Comments

Topics:

x3349
x2712
x63
x44
x10

asked: Aug 23, 2011 at 02:02 AM

Seen: 1218 times

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