- Home /
Question by
$$anonymous$$ · Aug 29, 2012 at 10:40 AM ·
loopfatal errorforloopgc
Fatal Error in GC
Why does this keep crashing Unity? is it just cause of all the for loops? Perhaps I should make it so each of the four loops triggers separately using bools?
#pragma strict
private var MoveDist : int;
var MoveSquareTotal : int = 0;
var MoveSquarePstvX : Transform;
var MoveSquarePstvZ : Transform;
var MoveSquareNegX : Transform;
var MoveSquareNegZ : Transform;
var MoveSquare : Transform;
var SquareCount : int = 0;
var ZCount : int = 0;
function LateUpdate () {
MoveDist = SelectionDetection.MoveDist;
MoveSquareTotal = (((SelectionDetection.MoveDist + 1) * 2) * SelectionDetection.MoveDist) + 1;
if (UnitDropDownMenu.Move == true && SquareCount < MoveSquareTotal){
for(var Draw1 = 0; Draw1 < MoveSquareTotal/4 ; Draw1 ++){
for(var SquareDrawPstvXZ = 0; SquareDrawPstvXZ < SelectionDetection.MoveDist; SquareDrawPstvXZ ++){
for(var SquareDrawPstvX = 1; SquareDrawPstvX < SelectionDetection.MoveDist - SquareDrawPstvXZ; SquareDrawPstvX ++){
var MoveSquarePstvX = Instantiate(MoveSquarePstvX, Vector3 (SelectionDetection.UnitPosX + SquareDrawPstvX,0.2,SelectionDetection.UnitPosZ + SquareDrawPstvXZ), Quaternion.identity);
SquareCount ++;
}
}
}
for(var Draw2 = 0; Draw2 < MoveSquareTotal/4 ; Draw2 ++){
for(var SquareDrawPstvZX = 0; SquareDrawPstvZX < SelectionDetection.MoveDist; SquareDrawPstvZ ++){
for(var SquareDrawPstvZ = 1; SquareDrawPstvZ < SelectionDetection.MoveDist - SquareDrawPstvZX; SquareDrawPstvZ ++){
var MoveSquarePstvZ = Instantiate(MoveSquarePstvZ, Vector3 (SelectionDetection.UnitPosX + SquareDrawPstvZX,0.2,SelectionDetection.UnitPosZ + SquareDrawPstvZ), Quaternion.identity);
SquareCount ++;
}
}
}
for(var Draw3 = 0; Draw3 < MoveSquareTotal/4 ; Draw3 ++){
for(var SquareDrawNegXZ = 0; SquareDrawNegXZ < SelectionDetection.MoveDist; SquareDrawNegXZ ++){
for(var SquareDrawNegX = 1; SquareDrawNegX < SelectionDetection.MoveDist - SquareDrawNegXZ; SquareDrawNegX ++){
var MoveSquareNegX = Instantiate(MoveSquareNegX, Vector3 (SelectionDetection.UnitPosX - SquareDrawNegX,0.2,SelectionDetection.UnitPosZ - SquareDrawNegXZ), Quaternion.identity);
SquareCount ++;
}
}
}
for(var Draw4 = 0; Draw4 < MoveSquareTotal/4 ; Draw4 ++){
for(var SquareDrawNegZX = 1; SquareDrawNegZX < SelectionDetection.MoveDist; SquareDrawNegZX ++){
for(var SquareDrawNegZ = 1; SquareDrawNegZ < SelectionDetection.MoveDist - SquareDrawNegZX; SquareDrawNegZ ++){
var MoveSquareNegZ = Instantiate(MoveSquareNegZ, Vector3 (SelectionDetection.UnitPosX - SquareDrawNegZX,0.2,SelectionDetection.UnitPosZ - SquareDrawNegZ), Quaternion.identity);
SquareCount ++;
}
}
}
var MoveSquare = Instantiate(MoveSquare, Vector3 (SelectionDetection.UnitPosX,0.2,SelectionDetection.UnitPosZ), Quaternion.identity);
SquareCount ++;
}
}
Comment
Your answer
Follow this Question
Related Questions
For loop and instantiate question 0 Answers
Intercompiler error.Fatal Error in gc 0 Answers
Why is this forloop crashing??? 2 Answers
gc: too many threads, crash using Unity 4.2 8 Answers
Shorten code with FOR loop 1 Answer