Hey… im looking to repeat a instantiate command for a set amount of time. and at a set time after game start…
ex. i want a couple of enemys to spawn after scene has been going for 30sec, and stop at 1min… then at 1min 10sec would like a diff object to instantiate untill the game clock hits a set time.
Have tried a few diff if statements, for loops and while loops, unity either crashes or loop does not work.
i already have a gametimer set up, just not sure of a appropriate way to use it for this task
That’s because a loop doesn’t run over multiple frames. The entire code of the loop is run in one shot, and if it doesn’t hit an end condition… well, it won’t end!
Also, consider that Time.time et. al. are only updated at the start of a frame. So if you use it as the end condition for a loop then the loop won’t ever end (because the loop stops the frame from ending, so the Time class never gets to change its values, so your loop’s end condition never gets hit).
As for invoke, it can take a delay. You can use a loop to set those delays, and then the calls will be made over time as you seem to intend. Alternatively, Update is called once per frame, so you could put stuff in there (not in a loop!) and use the Time class. Or, another alternative, you could use a coroutine (which might be what you mean by an “Ienumerator function”).
http://pastebin.com/fQyUkkJR here is the script guys… the first coroutine i have there at line 120 - 141 works as intended. loops 2 and 3(line 143 - 210)hey spawn hundreds and hundreds of enemys non stop… cant figure out why since they are the same damn loops (they wont be when im finished… thought using the same loop to set things up would make it easyer
thanks for your suggestions sofar
You really need to format your code. I tried to look at it, but it’s really discouraging when I can’t see where a while starts and ends without counting the number of {'s.
You can also post code on the forums, just put it in tags. If the code is very long, consider using [Spoiler] tags around the code.