|
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; }
(comments are locked)
|
The question has been closed Aug 11 '12 at 11:53 PM by Bunny83 for the following reason:
Duplicate Question
http://answers.unity3d.com/questions/299838/whats-wrong-about-what-i-am-doing.html
|
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: 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.
(comments are locked)
|
|
Duplicate question: http://answers.unity3d.com/questions/299838/whats-wrong-about-what-i-am-doing.html
(comments are locked)
|
