c# - Is a while loop that only yields the best practice for pausing a function? -


i have function calls first dialogue box, needs wait user press space bar before displays second dialogue box. can accomplish coroutine, yielding within while loop follows:

message.playmessage();      while (input.getkeydown (keycode.space) == false) {         yield return null;     }  message.playmessage(2); 

my question is: weird solution? feel there might actual function this, , fear maybe eating lot of system resources no reason.

it'll called once in frame, not expensive. , making wait function more convenient.

    ienumerator mymethod() {         message.playmessage();         yield return startcoroutine(waitforkeydown(keycode.space));         message.playmessage(2);     }      ienumerator waitforkeydown(keycode keycode)     {         while (!input.getkeydown(keycode))             yield return null;     } 

and call.

startcoroutine(mymethod()); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -