Search Unity

Overview: Coroutines & Yield page

Discussion in 'Documentation' started by Rodolfo-Rubens, Aug 5, 2014.

  1. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,197
    Hi, on this page:
    http://docs.unity3d.com/412/Documentation/ScriptReference/index.Coroutines_26_Yield.html
    the penult script it's saying that we can call coroutines without StartCoroutine in c#:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class example : MonoBehaviour {
    6. IEnumerator Do() {
    7. print("Do now");
    8. yield return new WaitForSeconds(2);
    9. print("Do 2 seconds later");
    10. }
    11. void Example() {
    12. Do(); // <------ doesn't work
    13. print("This is printed immediately");
    14. }
    15. }
    But it doesn't work, at least for me...
     
    Last edited: Aug 5, 2014
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You must always use StartCoroutine in C#, so the code there is wrong.

    --Eric
     
    Rodolfo-Rubens likes this.
  3. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,197
    Thanks again Eric, that's what I thought.