Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 cookies · Oct 23, 2011 at 04:40 PM · coroutinedelay

StartCoroutine troubles, not delaying/

I have a sprite that goes through waypoints by the Patrol function. I have

 transform.LookAt(target, Vector3.up);
 velocity = moveDirection.normalized * speed;

Which controls the movement of the sprite, if I comment it out, my sprite does not move. But when I have a Co-routine right before it, which delays for 9 seconds, but it is not delaying anything (but it's going into the coroutine as my "YEP" shows in debug)

 if (delayWaypoint.Length > 0)
              StartCoroutine("checkForDelay");
 transform.LookAt(target, Vector3.up);
 velocity = moveDirection.normalized * speed;

and the coroutine code:

 private IEnumerator checkForDelay()
     {
         int i = 0;
         foreach(int num in delayWaypoint)
         {
             if(num==currentWaypoint)
             {
                 Debug.Log("YEP:" + delayAmount[i]);
                 yield return new WaitForSeconds(delayAmount[i]);
 
             }
             i++;
         }
     }

So when I run it, in debug this is shown "YEP:9" but nothing is delayed.

Comment
Add comment · Show 1
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 cookies · Oct 23, 2011 at 08:40 PM 0
Share

hmm it seems like my logic needs to be in the coroutine for it to delay. that seems a bit silly

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by gruhm · Oct 24, 2011 at 11:37 AM

The code in a Coroutine after the yield return is going to run concurrently with the method that called it, So the delay effects code within the coroutine called after the yield.

If you simply want to delay execution for 9 seconds, take a look at Invoke.

Comment
Add comment · 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
-1

Answer by PatHightree · Oct 23, 2011 at 04:43 PM

Make sure you call your coroutine with :

 StartCoroutine(checkForDelay());
Comment
Add comment · Show 2 · 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 cookies · Oct 23, 2011 at 04:57 PM 0
Share

@PatHightree I have tried both checkForDelay() and "checkForDealy" both work the same :(

avatar image PatHightree · Oct 24, 2011 at 07:30 AM 0
Share

$$anonymous$$y bad, I didn't read your calling code... just blurted out my own most common mistake ;)

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to create a delay in a function being called in update? 2 Answers

Delay quitting and finish some coroutines 1 Answer

Function delay? 1 Answer

Coroutine not working as expected 1 Answer

Coroutine not running after yield return new WaitForSeconds 3 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