- Home /
Block ground generation
I have written a very simple script to make a ground of blocks.
var object : GameObject;
function Start () {
for(var x = 0;x < 100;x++)
{
for(var y = 0;y < 100;y++)
{
var cube = Instantiate(object,Vector3(x,y,0),Quaternion.Identity);
}
}
}
The object variable is the prefab that it should make the ground out of. In this case a cube. But when i run it there is no ground. And I am at 0,0,0 position in the world.
This would not create a ground. It would create a wall.
Answer by Statement · Aug 11, 2011 at 11:06 AM
It seems you're building a wall. x is left, y is up and z is forward. so you want to create them along the x/z axes. Also object is a reserved keyword in C#, I don't know how this translates to JS... But try renaming the object variable.
var prefab : GameObject; // Renamed, because of uncertainty
var height : float = -1.0f; // Adjust this to find a proper height...
function Start () {
for(var x = 0; x < 100; x++)
for(var z = 0; z < 100; z++)
Instantiate(prefab, Vector3(x, height, z), Quaternion.Identity);
}
Oh right yes i would create a wall but still nothing!
Well this is odd. Put a print("Hello world") inside Start to see if it runs at all. Is your script enabled?
Answer by Fabianlindfors · Aug 13, 2011 at 12:28 PM
It turned out that I used a capital I in Quaternion.identity ! Damn case sensitive!
And you got a null reference exception for that? JS doesn't fail to surprise me :)
Damn wierd but my instantiation is really slow! I instantiate 200 cubes at start but it takes like 10s to load! $$anonymous$$y computer is not slow!
Your answer
![](https://koobas.hobune.stream/wayback/20220612174613im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Problem with floor generator. 2 Answers
Cube made out of many voxels 0 Answers
Generate cubes in 5 areas 1 Answer
Mapping Cube to Sphere - Using 64 planes as a cube "side" 1 Answer