|
Ok, so I am having a problem with yield.WaitForSeconds but i may also be an issue with boolean referencing in a different script. Basically i have three states for my enemy: chase, patrol and deactivated. All of these states now work. The deactivated state is triggered by a boolean in attached to a console in the game. So when this console has been activated then the enemy is disabled. However i only want this to last a certain amount of time. Say 10 seconds. I tried using yield.WaitForSeconds(10); however for some reason this just makes my enemy spin around very slowly instead of going to it's waypoints. so everything works perfectly until i added in the section:
(comments are locked)
|
|
I have figured it out. Then make the function. just make it a function outside the update. Thanks syclamoth. By telling me you can't use yield inside of an update i was able to figure this out. Good job!
Nov 07 '11 at 02:43 PM
syclamoth
That's not a good solution. As long as your "state" variable is "deactivated" you will start a new coroutine every frame! That means if you have a framerate of 60fps you would start 600 coroutines. After 10 sec the first one will set state to "patrol" and would stop the "coroutine spam". All the other coroutines will end within the next 10 sec and all will set state to "patrol". This means, beside the incredible overhead, you can't set your state to something else for 10 sec.
Nov 07 '11 at 04:58 PM
Bunny83
(comments are locked)
|

You can't put a yield WaitForSeconds inside of Update- for something like this, I'd recommend making your own coroutine-based loop, which you call from Start (and then don't use Update).