Unity Community

Results 1 to 2 of 2

  1. Location

    How to pause any coroutine according to your global pause state :


    as coroutines are very important in optimization processes, making them compatible with a game paused state could be vital.

    So here we go :

    In your class containing those coroutines (or in any abstract/singleton you want), put these functions :

    1. public Coroutine _sync(){
    2.         return StartCoroutine(PauseRoutine())
    3.     }
    5. public IEnumerator PauseRoutine(){
    6.         while (_myPauseState) {
    7.             yield return new WaitForFixedUpdate()
    8.         }
    9.         yield return new WaitForEndOfFrame();   
    10.     }

    with _myPauseState being your global pause state.

    then in any Coroutines, put this at the end (or at any place you want to check for a pause) :

    1. yield return _sync();

    I personally prefer to put the first code block into a generic baseClass, derived from MonoBehaviour , and then derive all my other "pause-able" classes from it. So I don't have to rewrite the block in all the new pause-able classes.

  2. Posts
    Just wanted to say thank! Great script!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts