- Home /
Create a grid on a cube?
Hello! :) I'm working on a game which needs a grid. I have a 10x10 flat cube which I use as my "grid area", what I want to do is creating a grid inside this cube which resizes according to a parameter. For example if I want a 5x5 grid, the grid area will consist of 25 cubes of the same size (like a normal grid d'oh).
I have a simple script that creates a grid and instatiates objects according to the grid: var prefabCount=0; var tGridX=0; var tGridY=0; tubesArray=new GameObject[gridY,gridX];
var posY=-1.0;
for (var y= 0; y< gridY; y++){
for (var x=0; x<gridX; x++){
selectPrefab(gridChars[prefabCount]);
var pos=Vector3(x, posY, 0)*spacing;
var temp= Instantiate(myPrefab, pos, Quaternion.identity);
tubesArray[y,x]=temp;
tubesArray[y,x].GetComponent(CubeProperties).setPosition(y,x);
prefabCount++;
}
posY=posY+1.0;
}
}
This works but I have to set Y and X positions and prefabs sizes to fit the screen (it's an Android project btw). I need a better grid system which allows me to change the size of the prefabs I have to instantiate, to fit the square tile size of the grid without changing it manually everytime.
It's way more difficult to explain than I tought :( I tought I could do just like in real life where i just take the size of the area (10x10) and divide it by 3 if i want a 3x3 grid; so each grid's tile would be of around 3,33, and set the prefab size to that; but it doesn't work D:
Any suggestions? Solving this problem would boost my project a lot!
PS. Forgot to say that the prefabs are just square sized gameobects sprites, don't know it is useful
To better explain what I want to do: here's an image of flow free, I want to do the exact same thing (the play area stays the same, the size of squares is reduced to create a bigger grid), but I also need a way to scale down a sprite gameobject to fit the square size and instantiate it.
$$anonymous$$ight be easier to leave the grid sizes the same and change either the camera's field of view (if you are using a perspective camera) or the camera's orthographic size (orthographic camera) to allow the squares to fit the view.
That could work indeed! I'm using an orthographic camera. I'll go with this solution for now thanks.
I'd still like to know how something like flow free grid area is made tho
Your answer
Follow this Question
Related Questions
Grid and or Tile System 0 Answers
How can I compare two tilemaps by color? 1 Answer
How to stack components on a Tile/Tilemap 0 Answers
How to create a rotating tiles with walls on edges of tiles? 0 Answers
How do you find adjacent tiles of the same type in grid array [x,y].type == [x+1,y].type 0 Answers