Nested startCoroutine

if i nested startcoroutine like the folloing code:

  IEnumerator ParallaxOffset()
    {
//        yield return new WaitForSeconds(0.3f);
        var offset = Time.time * -OffsetSpeed;
        if (isVertical)
        {
            renderer.material.mainTextureOffset=new Vector2(0,offset);
        }
        else
        {
            renderer.material.mainTextureOffset=new Vector2(offset,0);
        }
        StartCoroutine(this.ParallaxOffset());
        Debug.Log("i am start coroutine ");
        yield return new WaitForSeconds(0.5f);
    }

  my unity will be crashed .

if i remove the annotation, this is ok.

  IEnumerator ParallaxOffset()
    {
        yield return new WaitForSeconds(0.3f);
        var offset = Time.time * -OffsetSpeed;
        if (isVertical)
        {
            renderer.material.mainTextureOffset=new Vector2(0,offset);
        }
        else
        {
            renderer.material.mainTextureOffset=new Vector2(offset,0);
        }
        StartCoroutine(this.ParallaxOffset());
        Debug.Log("i am start coroutine ");
        yield return new WaitForSeconds(0.5f);
    }

  

 

Offset with renderer.material.mainTextureOffset  is relative the lcoal UV xy coordinate

posted @ 2014-07-05 13:47  penney  阅读(229)  评论(0)    收藏  举报