Search Unity

Coroutines with multiple arguments

Discussion in 'Scripting' started by madcalf, May 3, 2006.

  1. madcalf

    madcalf

    Joined:
    Jan 12, 2006
    Posts:
    56
    What's the best way to start a coroutine that has multiple arguments. For example:

    Code (csharp):
    1. // plays an animation and sends a message when done.
    2. function PlayAnimWithCallback(aAnim, aObject, aCallback) {
    3.     if (!aAnim.isPlaying) {
    4.         aAnim.Play();
    5.         yield WaitForSeconds(aAnim.clip.length);
    6.         aObject.StartCoroutine(aCallback);
    7.     }
    8. }
    Using the following gives an error along the lines of: "no appropriate version of '...StartCoroutine' for the argument list (System.String, System.Animation, System.Object, System.String) could be found."

    Code (csharp):
    1. yield StartCoroutine("PlayAnimWithCallback", snakeStrikeAnim, gameControllerScript, "StrikeAnimDone");
     
  2. hsparra

    hsparra

    Joined:
    Jul 12, 2005
    Posts:
    750
    You could pass an array, a dictionary, or your own special object with your arguements.