- Home /
Unity Freezes Permanently
Upon pressing the play button in my Unity scene, it completely freezes and is unresponsive. The window itself does not show the usual (not responding) text at the top. This is the code I am attempting to run, which is supposed to generate a plane of cubes at different heights in a 10x10 configuration. No error message is given, and I have to kill the program with Task Manager.
using UnityEngine;
using System.Collections;
public class Terrain_Generator : MonoBehaviour
{
public GameObject Target_Obj;
public int width;
int iteration;
public int length;
public int height;
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (iteration <= height)
{
for (int i=0; i<length; i = i + 1)
{
float horizPos = Random.Range (height, -height);
Object.Instantiate (Target_Obj, new Vector3 (iteration, horizPos / 10, i), Quaternion.identity);
if (i == length - 1)
{
i = 0;
iteration = iteration + 1;
}
}
}
}
}
Answer by revolute · May 18, 2015 at 06:43 AM
Infinite looping.
if(i == length -1){ i = 0; <--- your trouble. This is reset everytime i hits length -1. }
Thanks a bunch, man. Don't even know why I put in that little snippet. xD
Your answer
Follow this Question
Related Questions
Terrain Triangle Generation 1 Answer
Instantiate 697283 trees by script? Crash! 2 Answers
My VR game build crashes when the terrain is enabled. 0 Answers
random height 2d Generator 0 Answers