- Home /
 
               Question by 
               sourav13 · Sep 02, 2016 at 10:24 AM · 
                coroutineinvokerepeating  
              
 
              Coroutine in place of InvokeRepeating in need of start at time parameter
 IEnumerator SendSpriteForward(int no, Coroutine n,int prevhighestorderInlayer)
 {
     while (true) {
         StopCoroutine (n);
         for (int i = 0; i < gameObjectsContainer.transform.childCount; i++) {    
             gameObjectsContainer.GetChild (i).transform.GetChild (no).GetComponent<SpriteRenderer> ().sortingOrder = gameObjectsContainer.GetChild (i).transform.GetChild (prevhighestorderInlayer).GetComponent<SpriteRenderer> ().sortingOrder + 1;
         }
         n = StartCoroutine (GenericCoroutine (no, 0));
         yield return new WaitForSeconds (6);
     }
 }
I need to call this coroutine in start method at different times .
In start Method i want to call them as such
           StartCoroutine(SendSpriteForward(5,one,0));  //start this call at 6 second 
     StartCoroutine(SendSpriteForward(4,two,5)); // this at 7 
     StartCoroutine(SendSpriteForward(3,three,4));//8
     StartCoroutine(SendSpriteForward(2,four,3));//9
     StartCoroutine(SendSpriteForward(1,five,2));//10
     StartCoroutine(SendSpriteForward(0,six,1));//11
and so . The Repeating functionality has been attained but the start time i need to. Thank you.
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by etaxi341 · Sep 02, 2016 at 10:33 AM
You could start a coroutine in your Start method like this
 void Start()
 {
     StartCoroutine(SpriteSwaps());
 }
 IEnumerator SpriteSwaps()
 {
    return yield WaitForSeconds(6f);
    StartCoroutine(SendSpriteForward(5,one,0));
    return yield WaitForSeconds(1f);
    ...
 }
So this Coroutine "SpriteSwaps" gets called in your Start ant then waits until the next sprite has to be set.
Thank you very much . Nothing can be more clear than this although now i have a coroutine , inside a coroutine , which is yet inside another coroutine , yippee something like Inception haha .
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                