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 /
This question was closed Apr 01, 2015 at 02:12 PM by hug0 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by hug0 · Dec 20, 2013 at 05:07 PM · androidjavascriptfunctionyield

yield WaitForSeconds don't work

Hi, yields WaitForSeconds in this code is not working and I don´t know why, someone can help me?

 var clock_b1 : Texture2D[];

 var clock_b : GameObject;

 var i = 0;
 
 function PlayAnim () {
             
 if(i < 11 ){
                     
 
 i++;
             
 clock_b.guiTexture.texture = clock_b1[i];
 yield WaitForSeconds (1);
             
 }else{
         
 i=0;
 }
 }
Comment
Add comment · Show 4
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 sdgd · Dec 20, 2013 at 05:10 PM 0
Share

have you tried invoke?

like:

 void function(){
     invoke("FunctionName", 1f);
 }
 
 FunctionName(){
     Debug.Log("asdf");
 }

it's much easyer to understand at least for me

avatar image hug0 · Dec 20, 2013 at 05:16 PM 0
Share

Yes, I invoke the function PlayAnim in the update function,

all the code are working except the yield

avatar image Kiloblargh · Dec 20, 2013 at 05:37 PM 0
Share

It is too working. Every frame, PlayAnim() will be called and i will be incremented by 1. The timer will reach 11 in 11 frames. One second later, all the code after yield WaitForSeconds (1); will be executed, finishing in 1 second and 11 frames. There is no code after the yield so there you go.

yield WaitForSeconds makes the function it is in wait, but it does not prevent that function from being called again multiple times, does not prevent Update from being called every frame, and does not make the entire game wait. That is its intended behavior and it is much more useful that way.

avatar image robertbu · Dec 20, 2013 at 05:45 PM 0
Share

There is not enough of your logic/script here to find your problem. In particular we need to see where/how "PlayAnim" is called. The typical problem is folks calling functions with a 'yield' form Update().

1 Reply

  • Sort: 
avatar image
1

Answer by iwaldrop · Dec 20, 2013 at 05:18 PM

Don't call it from update. Don't make it a coroutine, and instead use invoke repeating.

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

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Use yield WaitForSeconds to delay mouseover on a gameObject? (JS) 1 Answer

Coroutine a function within a loop? 1 Answer

Accessing function from another script won't work 1 Answer

Error BCW0015 and BCW0023 but they both work, how to solve it? 1 Answer

running code outside of update! 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