Search Unity

where is yield return new StartCoroutine() in 2019

Discussion in 'Scripting' started by vfxjex, Feb 13, 2020.

  1. vfxjex

    vfxjex

    Joined:
    Jun 3, 2013
    Posts:
    92
    Code (CSharp):
    1.     IEnumerator Test()
    2.     {
    3.         yield return new StartCoroutine(CoroutineTest());
    4.     }
    5.  
    6.     IEnumerator CoroutineTest()
    7.     {
    8.         yield return null;
    9.     }
    Above is a simple code of yield return new StartCoroutine but it could not be found when using yield return new.
     
  2. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    689
    StartCoroutine
    is a method on
    MonoBehaviour
    , not a type. Using
    new
    here is incorrect and causes C# to look for a type, which it can't find. Remove it and the code should work fine.

    You do need to use
    new
    with
    WaitForSeconds
    and other yield instructions, those are types and not methods and require a
    new
    to instantiate.
     
    Ryiah likes this.
  3. vfxjex

    vfxjex

    Joined:
    Jun 3, 2013
    Posts:
    92
    hahaha sorry my bad...
    Thanks Adrian
     
unityunity