Can someone give me a hand creating a grid of blocks.
I am trying to create a repeating grid of block on a grid of 9x9 approaching down a path.
So far, i have a grid of blocks using this script from the wiki:
var cube : Transform;
function Start () {
for (var y = 0; y < 9; y++) {
for (var x = 0; x < 9; x++) {
var cube = Instantiate(cube, Vector3 (x, y, 0), Quaternion.identity);
}
}
}
and moving in the z axis with this:
function Update () {
transform.Translate(0, 0, -speed*Time.deltaTime);
}
My problem is i am trying to have them appear in a random tetris-like manner and come down the path. The blocks are destructible so if a block is destroyed it should be reset in a random position at the point of origin within the 9x9 grid.
Any help would be greatly appreciated.
Is there no one that can help?
It’s not clear at all what you’re asking for help with.
In addition, there’s a good number of people who simply skip right over posts where code is not presented in a bbcode codeblock, as it’s usually near impossible to read.
So my advice would be to put it into a proper code block, then try and be more precise about which part the code you posted isn’t working.
Hi Quitus
Thanks for responding. I guess i was not clear on what i was asking. I am programming noob and I am still learning to ropes of the forums so please bear with me. I will try to explain more clearly.
I am basically trying to create a random grid of blocks that will approach down a corridor.
See this link for a similar idea to what I am trying to achieve. http://forum.unity3d.com/viewtopic.php?t=27118&postdays=0&postorder=asc&start=15
Der Dude actually helped me a bit with some code but i cannot get it to work. This is the sample that he provided me with:
I hope this clarifies what I’m trying to do.
Also, can you tell me how to put my code in a bbcode format so it reads better on the posts? Sorry for such i novice question.
Thanks!
int gridwidth = 5;
Transform[,] grid = new Transform[gridwidth, gridwidth];
for(int i = 0; i < obstacleCount; i ++);
{
int x = Random.Range(-6,6);
int y = Random.Range(-6,6);
if(grid[x, y] == null);
{
grid[x, y] = Instantiate(prefab, pos, Quaternion.identity);
}
}
When you reply to a post, there’s a button at the top which says code. Click on it, then it’s a simple matter of inserting your code in-between those bbcode tags.
var myString = "It then shows up like this";
Which is far easier to understand!
There it goes…
Thanks for that Quitus. Now if only someone can help me figure it out the problem.