• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sourav13 · Sep 02, 2016 at 11:46 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

56 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Pause GameLoop with Pause Button 1 Answer

How can I get my platforms to randomly appear when not activated by button 1 Answer

convert timer from update() to coroutine or invokerepeating 0 Answers

How i can make a function call and then after 15 sec another function call during this function call the first one stops.And this process keep repeating again and again. 1 Answer

How to get function to run every x seconds and then every y seconds? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges