x


Create a grid of transform instances

I really need to do this, but im pretty new programing so i dont know where begin. What i need is create a grid with colums and rows to instantiate a series of prefabs on scene on determinate distance, and be able to put and change them within the inspector. I was thinking about some loop var, but i cant figure how to do it. Aprecciate so much your help.

alt text

more ▼

asked Sep 02 '11 at 01:08 PM

NE07HEKIN6 gravatar image

NE07HEKIN6
1 2 2 2

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

2 answers: sort voted first

The Manual page on Instantiate has sample code how to do this.

more ▼

answered Sep 02 '11 at 01:13 PM

save gravatar image

save
8.3k 22 31 63

One only problem, this is good to instantiate the same object, do you know how to make it to instantiate prefabs from an array?? Thanks again

Sep 02 '11 at 01:49 PM NE07HEKIN6

What does the array look like? Do you have different objects for every grid tile, objects that repeat or objects that is defined by you where they should be? How many objects are there?

Basically just bring that array (if you have it constructed) into the for-loop and go wild with it (if(objArray[i]), if(i%5) and so forth). :-)

Sep 02 '11 at 02:09 PM save

they are prefabs that make the scenary of the game, every one is put in a number on the array, 1, 2, 3, so on, so if you change a prefab you can modify the scenary, so are some prefabs that are repeated and some that have no repetition. The array looks like the drawing i put up, its a x*y array. I can do this by hand, but i think it would be nicer to find out a code to instantiate prefabs on the inspector in an automatic way.

Sep 02 '11 at 02:18 PM NE07HEKIN6
(comments are locked)
10|3000 characters needed characters left

I already did it, was simple after all, i post it in case someone needs it

var cube : Transform[];

function Start () {

for (var y = 0; y < 5; y++)

{ for (var x = 0; x < 5; x++)

{ for (var z = 0; z < x*y; z++) { var cube = Instantiate(cube[z], Vector3 (x, y, 0), Quaternion.identity); } } } }

more ▼

answered Sep 02 '11 at 02:25 PM

NE07HEKIN6 gravatar image

NE07HEKIN6
1 2 2 2

(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:

x1725
x276
x88

asked: Sep 02 '11 at 01:08 PM

Seen: 948 times

Last Updated: Sep 02 '11 at 02:25 PM