problem with WaitForSeconds

hi to all :wink:
i have a lot of problems to implement a method that uses a WaitForSEconds function;
i explain better my situation.

in Update function i call a method that use waitforsecond :

void Update() {

IEnumerator Wait() {
   yield return new WaitForSeconds(5);

but in this way nothing happened.
somebody can help me?
thanks :wink:

Well that code won’t do anything unless you have other code before or after the WaitForSeconds part. However, you’re using a Coroutine in Update which won’t work if you want it to block the execution path of Update. It will work if you are happy just creating a new coroutine that doesn’t block, though there is another way. Check out CoUpdate, a solution for having an Update that support Coroutines. This one is written in JS, but the idea is easily carried over to C#. Just make a Coroutine that is booted up during Start().

in c# is not allowed to do : yield WaitForSeconds(5);

You need to use StartCoroutine when using C#. However, if you do that, you’d be starting a new instance of the Wait coroutine every frame. You can’t make Update pause or yield; it always runs once every frame no matter what. The simple solution is to just not use Update. Update is for things that run once every frame…if you don’t want that, don’t use Update.