- Home /
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.
Answer by Jesse Anders · Mar 17, 2011 at 12:40 PM
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).
Your answer
Follow this Question
Related Questions
Adding Imperfections? 1 Answer
Grid matching issue 0 Answers
How to instantiate a prefab at mouse pos 1 Answer
Add instantiate object to GameObject[] 2 Answers