x


Creating a grid of cubes.

Hi, sorry pretty new to Unity but I'll try to explain what I am trying to do.

I am trying to create a grid of 3d cubes, say 30 cubes * 50 cubes. Eventually I want to develop it so when the mouse moves over the a cube in the grid it rotates. But thats not the issue at the moment.

So my question is, simply is there an easy way to create a grid of cubes instead of doing it by hand manually?

Akin to the array tool in Cinema4D and in Actionscript 3:

public function CubeGrid(){

            var rowY:Number = 0;                    
            for (var i:int = 0; i < 190; i++) {
                var myCube = new CubeMenu(["//**//"],100);
                myCube.x = 0 + ((i % 10) * 200);
                if (i % 10 == 0) {
                    rowY += 200;
                }
                myCube.y = rowY;
                addChild(myCube);


            }

Thanks in advance.

*Mods if my Tags are wrong please amend.

more ▼

asked Mar 17 '11 at 10:49 AM

Sisyphus gravatar image

Sisyphus
9 3 4 9

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

1 answer: sort voted first

If you want to create the cubes via code, it would probably look something like what you've posted (i.e. a single or double loop, with a cube created for every iteration). I can't really think of any alternate approach that would be simpler or more straightforward than that.

You could also create the grid by hand in the editor pretty quickly by copying and pasting (e.g. create one row and copy-and-paste it N times). Or, you could write an editor script to create the grid, after which the cubes would be saved with the scene (meaning you wouldn't have to re-create them in code each time the level was loaded).

more ▼

answered Mar 17 '11 at 12:40 PM

Jesse Anders gravatar image

Jesse Anders
7.3k 7 17 48

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

x1678
x1363
x492
x289
x268

asked: Mar 17 '11 at 10:49 AM

Seen: 2170 times

Last Updated: Mar 17 '11 at 10:49 AM