- Home /
Unity crashes because of script
hello, i know this is a noobie question but i cant figure it out, i have a loop script and when i try to run it unity crashes. it works fine with everything else its just this script. any help is appreciated
#pragma strict
var i:int=0;
var Prefab:GameObject;
var lastUpdate:float=0;
function Start () {
}
function Update () {
while(i<10){
print(i);
if(Time.time - lastUpdate >= 1f){
lastUpdate = Time.time;
i++;
Instantiate(Prefab,transform.position,transform.rotation);
}
}
}
im an idiot, this scipt was supposed to be an if not a loop ,sorry people.
Answer by yashpal · Dec 23, 2014 at 05:17 AM
@husainh00, here "i" is never changed. Here "while" is continuous running because "i" is always less than 10. so unity stuck and crash.
I don't know what you are trying to do, but this is bad. As stated by yashpal, you are creating an infinite loop within Update (which runs once every frame).
Answer by SeasiaInfotechind · Dec 23, 2014 at 05:51 AM
Here Unity Crashes because you are running an infinite loop as stated by YashPal.
Value of "i" never changes here.
as lastUpdate = Time.time ,So Time.time-lastUpdate < 1f so " i " will not be incremented.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
What can cause Unity to crash? 3 Answers
Unity stops working when I play the game in editor 2 Answers
Active/Desactive Cameras 1 Answer
Is this loop infinite? 2 Answers