I'm obviously not a great programmer, and I'm having a problem at the moment that I think stems from a fundamental misunderstanding of coroutines and yield.
Basically, I have a function used to display GUI texts according to a numbered variable when the player activates a terminal etc. I want the GUI message to display until the player hits a key, and then load the next message ( very similar to this, but I can't figure it out)
So the two scripts are as follows (names simplified):
Now, as I (mis)understand it, yielding the commands in Script 1 means that Script 1 will wait until each function is complete before moving to the next one. My problem is that I can't get Script 2 (especially the MoveOn function) to work. I can get an infinite loop(crash), or simply cycle through all three commands in Script 1 instantly. I have read in other posts that while loops need a yield to prevent infinite looping, but it seems to me that putting in a yield simply gives control back to Display(), defeating the purpose of the loop (i.e. waiting for a keypress before ending)
BTW, it works fine using
Any ideas what I'm missing here? Any commments much appreciated, and feel free to point out how little I know!
Yeah, no. You should look for Input in an Update function, set whatever variables would indicate progress there, and use those in the OnGUI function to display which ever UI bits you want at that stage. OnGUI would 'wait' for the user to type something in, for example. I suppose you might use Yield and such to do such things, but it would not be 'best practice'
answered Mar 01 '12 at 12:49 AM