- Home /
for loop error
I have a script with for loops to generate world. It worked fine for a month or so, but now it gives me this error i cant figure out what is wrong.
this is the script
var height = 64;
var width = 128;
var cube : GameObject;
function Start () {
Spawn();
}
function Spawn(){
for(var w = 0; w < width; w++){
for(var h= 0; h < height; h++){
Instantiate(cube, Vector3(h, 0, w), Quaternion.identity);
}
}
}
As it says "an error occurred that wasn't supposed to". This for loop shouldn't in itself produce this error. Restart Unity or try a reinstall.
This code compiles fine for me. Are you sure this is the script with the error? Note that when you get a long list of errors like this, only the first error or two usually matter...and you are not showing us that error. Find the first error on the list and double click on it to see what file and line are producing the error.
i changed object that I instantiate with basic cube and it works fine, without any errors. but I dont understand what seems to be the problem with objects that I instantiated before, since it is just basic cube with simple texture
As mentioned before, you need to double click on the top error to see in what script and line you are getting an error. Without the actual error and the script that is generating the error, we cannot help you.
it highlight me this line of code
Instantiate(cube, Vector3(h, 0, w), Quaternion.identity);
,but as I said before the problem is actually in objects I instantiate.
Your answer
