Search Unity

C# yield

Discussion in 'Scripting' started by mnrabaglia1234, Aug 24, 2009.

  1. mnrabaglia1234

    mnrabaglia1234

    Joined:
    Jul 27, 2009
    Posts:
    15
    I have a doubt with the correct sintax of this JS sentence in C#:

    remoteTexture = new WWW(remoteTextureURL);
    yield remoteTexture;

    How can i give the the same behaviour with C#?
     
  2. tomvds

    tomvds

    Joined:
    Oct 10, 2008
    Posts:
    1,028
    Something like this:
    Code (csharp):
    1. IEnumerator TheFunctionWaitingForWWW()
    2. {
    3.     // ...
    4.     remoteTexture = new WWW(remoteTextureURL);
    5.     yield return remoteTexture;
    6.     // ...
    7. }
    You will need to call TheFunctionWaitingForWWW() using StartCoroutine, or it won't work:

    Code (csharp):
    1. StartCoroutine(TheFunctionWaitingForWWW());
     
  3. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    This is covered in the Scripting Reference's entry for StartCoroutine.
     
  4. mnrabaglia1234

    mnrabaglia1234

    Joined:
    Jul 27, 2009
    Posts:
    15
    Thanks!!! Its works!