x


[Closed] 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;

}

more ▼

asked Aug 11 '12 at 08:09 AM

Theacesofspades gravatar image

Theacesofspades
13 1 3 11

(comments are locked)
10|3000 characters needed characters left

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


2 answers: sort voted first

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.
more ▼

answered Aug 11 '12 at 11:53 PM

drak0 gravatar image

drak0
33 1 2

(comments are locked)
10|3000 characters needed characters left
more ▼

answered Aug 11 '12 at 11:33 AM

zyzyx gravatar image

zyzyx
226 1 3

(comments are locked)
10|3000 characters needed characters left

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3736
x1951
x110
x5

asked: Aug 11 '12 at 08:09 AM

Seen: 198 times

Last Updated: Aug 11 '12 at 11:53 PM