- Home /
Duplicate Question
http://answers.unity3d.com/questions/299838/whats-wrong-about-what-i-am-doing.html
I am having spawning problems.
Hello everyone, i am having trouble with my enemy spawner. When i play the game it creates the fist enemy fine, but then it creates a million enemys at once. How can i make it so it creates on every spawntime? My code is :
var spawntime = 2; var enemy : Transform;
function Start () { var i = 0;
for(i=0; i>-1; i++) { yield WaitForSeconds(spawntime); Instantiate(enemy,transform.position,transform.rotation); spawntime -=0.1; } }
function Update () { var randomx = Random.Range(-4.5,4.5); transform.position.x = randomx;
}
Answer by drak0 · Aug 11, 2012 at 11:53 PM
Read the documentation man , I told you in your previous question, you have an infinite loop there, the condition in the for loop will never be false.This is what I'm talking about:
for(i=0; i>-1 ;i++)
That ( the part with bold) is the condition that stops your loop.While your condition is true, it will keep adding 1 to i.But your condition will never be false , because you check if i is greater than -1 , and that can't happen if you start with i being 0 and adding 1 to it.
Answer by zyzyx · Aug 11, 2012 at 11:33 AM
Duplicate question:
http://answers.unity3d.com/questions/299838/whats-wrong-about-what-i-am-doing.html
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
A node in a childnode? 1 Answer
Analysing player metrics help 0 Answers
I made a better shader how do i fix[add _Shadow Strength]help???>Sorry that im asking for to much 1 Answer
How can i spawn one by one? 2 Answers