Example

Here is a simple example of using MEC coroutines:

using UnityEngine;
using System.Collections.Generic;
using MovementEffects;

public class Testing : MonoBehaviour
{
    void Start ()
    {
        CoroutineHandle handle = Timing.RunCoroutine(_RunFor10Seconds());

        handle = Timing.RunCoroutine(_RunFor1Second(handle));

        Timing.RunCoroutine(_RunFor5Seconds(handle));
    }
	
    private IEnumerator<float> _RunFor10Seconds()
    {
        Debug.Log("Starting 10 second run.");
        
        yield return Timing.WaitForSeconds(10f);

        Debug.Log("Finished 10 second run.");
    }

    private IEnumerator<float> _RunFor1Second(CoroutineHandle waitHandle)
    {
        Debug.Log("Yielding 1s..");

        yield return Timing.WaitUntilDone(waitHandle);

        Debug.Log("Starting 1 second run.");

        yield return Timing.WaitForSeconds(1f);

        Debug.Log("Finished 1 second run.");
    }

    private IEnumerator<float> _RunFor5Seconds(CoroutineHandle waitHandle)
    {
        Debug.Log("Yielding 5s..");

        yield return Timing.WaitUntilDone(waitHandle);

        Debug.Log("Starting 5 second run.");

        yield return Timing.WaitForSeconds(5f);

        Debug.Log("Finished 5 second run.");
    }
}

This is the output:

Starting 10 second run.
Yielding 1s..
Yielding 5s..
Finished 10 second run.
Starting 1 second run.
Finished 1 second run.
Starting 5 second run.
Finished 5 second run.

 
Here’s an example of how to use MEC from UnityScript:

import System.Collections.Generic;
import MovementEffects;
     
function Start() {
    Timing.RunCoroutine(_TestCoroutine());
}
     
function _TestCoroutine() : IEnumerator.<float> {
    Debug.Log("TestCoroutine: Starting...");
     
    var handle : CoroutineHandle = Timing.RunCoroutine(_TestWait());
     
    yield Timing.WaitUntilDone(handle);
     
    Debug.Log("TestCoroutine: Finished!");
}
     
function _TestWait() : IEnumerator.<float> {
    for (var i : int = 0; i < 5; i++) {
        Debug.Log("TestCoroutine: " + i);
        yield;
    }
}

Output:

TestCoroutine: Starting...
TestCoroutine: 0
TestCoroutine: 1
TestCoroutine: 2
TestCoroutine: 3
TestCoroutine: 4
TestCoroutine: Finished!