- Home /
Duplicate Question
Procedural Generation generating infinitely?
Unfortunately, I've written some code and have run into some errors executing it without crashing Unity. I've placed some code that should place cubes above the original cube Number
times. However, when I run the code, it starts generating A TON of cubes and Unity freezes. Here is my code:
using UnityEngine;
using System.Collections;
public class GenerationController : MonoBehaviour {
public GameObject genCube;
public Quaternion rot;
public int J;
public int Number;
// Use this for initialization
void Start () {
float a = 0;
while(a<Number)
{
Vector3 positionOver = new Vector3 (genCube.transform.position.x, genCube.transform.position.y + J, genCube.transform.position.z);
Instantiate(genCube, positionOver , rot);
a++;
}
}
// Update is called once per frame
void Update () {
}
}
If you can provide any, please help.
There are some issues in this script, but nothing that should hang Unity. I ran a test and it runs fine. What do you have 'Number' set to?
Sorry, that didn't solve the infinity issue. But thanks for the syntax help, I appreciate it.
Sorry I couldn't be of any more help, I can't find anything wrong with it on my end. Everything runs fine.
Follow this Question
Related Questions
Concerns about performance issues with infinite sized game 1 Answer
Is this loop infinite? 2 Answers
Infinite Looping Crash 2 Answers
Unity4 crashes with 1.5M of cubes using MeshTopology 1 Answer
2d Random object placement help? 1 Answer