Hi all,
sorry to ask but i can’t figure this one out.
error = Object reference not set to an instance of an object
world.createRandomWorld
script:
public GameObject cube; //assign in the inspector
public GameObject[][][] cubes;
int sizex;
int sizey;
int sizez;
// Use this for initialization
void Start()
{
sizex = 10;
sizey = 10;
sizez = 10;
GameObject[,,] cubes = new GameObject[sizex,sizey,sizez];
createRandomWorld();
}
void createRandomWorld()
{
for (int countx = 0; countx < sizex; countx++)
{
for (int countz = 0; countz < sizez; countz++)
{
for (int county = 0; county < Random.Range(sizey - (sizey - 1), sizey); county++)
{
//cubes[countx][county][countz] = cube; //doesn’t work
//cubes[countx][county][countz] = (GameObject) cube; //doesn’t work
cubes[countx][county][countz] = cube as GameObject; //doesn’t work
}
}
}
}
I think you should use public GameObject[,,] cubes; instead of public GameObject[][][] cubes;.
Second thing you have to change GameObject[,,] cubes = new GameObject[sizex,sizey,sizez]; to cubes = new GameObject[sizex,sizey,sizez];. Third change cubes[countx][county][countz] = cube; to cubes[countx,county,countz] = cube; .