- Home /
How to make sure something is run after all the OnGUI calls
My application performs an action when the player taps on the screen. The problem is, hitting the Pause button also counts as a tap event. I've tried everything, but the strange nature of OnGUI (being called several time by frame and at unpredictable moments) keeps me from preventing such an action.
I want to be sure that no interaction was made with the interface during the current frame before I start checking any other kind of events. Interface events for a given frame must be solved before any other kind of event. The player must not be able to perform any kind of action if the interface has been touched.
How do I do such a thing ?
Answer by Sisso · May 21, 2014 at 05:00 PM
The normal solution is to not use OnGui, but a library like NGUI.
I can't see any good solution without hack, like check Time.timeScale > 0 (not paused) before process the touches.
Try to look into GUIUtility.hotControl if it helps.
funny how absolutely all our problems in our game come from the fact the previous developer used OnGUI... yet my time isn't scheduled on re-writing all that code... sigh... thanks for the help, looks like a good lead to do a workaround, while I try to convince people that we need to completely re-write our GUI.
Answer by trigraph · Feb 17, 2017 at 09:13 AM
I know it's an old question, but for reference:
IEnumerator DoStuff()
{
yield return new WaitForEndOfFrame();
// Do stuff
}