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
1
Question by Giannis7312777 · Nov 10, 2013 at 11:46 PM · yield waitforseconds

yield WaitForSeconds problem?

Hello everyone.

I've create a 'yield WaitForSeconds()' and I want a message to change after specific seconds. My problem is that in the first 'yield WaitForSeconds()' I set the seconds to 2 for example, and on the second 'yield WaitForSeconds()' I set the seconds to 1. The problem is that it only reads the first 'yield WaitForSeconds()' and then it skips it all. Here is my code, please help me :)

 function second_textGUI(){
     first_text_message = "(Sshhh!!)";
     yield WaitForSeconds(3);
     first_text_message = "(Hmm.. who is he?)";
     yield WaitForSeconds(2);
     first_text_message = "(He might be the murderer!!!)";
     yield WaitForSeconds(3);
     first_text_message = "";
     second_en = false;
 }

Any help is appriciated :)

Edit: Is there any other way similar to yield WaitForSeconds() ?

Comment
Add comment · Show 5
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 Huacanacha · Nov 11, 2013 at 12:05 AM 1
Share

Do you mean the coroutine doesn't continue executing after the first yield WaitForSeconds call? Have you added Debug.Logs to confirm what gets executed? How is first_text_message declared and where is it used?

Initially I though your were declaring the function wrong, then I noticed it was UnityScript not C# :)

avatar image liszto · Nov 11, 2013 at 12:08 AM 1
Share

no error ? I never code in js but for me this is right.

avatar image robertbu · Nov 11, 2013 at 12:22 AM 1
Share

Are you calling second_textGUI() multiple times in either Update() or OnGUI()?

avatar image Giannis7312777 · Nov 11, 2013 at 10:22 AM 0
Share

@robertbu I call it only in OnGUI() function.

@Huacanacha I've checked it with Debug.Log, but it works only if all the yield WaitForSeconds have the SA$$anonymous$$E seconds.. If I check atleast on yield WaitForSeconds then it going to mesh up.. :(

@liszto I get no erros.. but it's not working properly

avatar image Berenger · Nov 11, 2013 at 10:38 AM 1
Share

Is it called once during an event (a button pressed) or inside the GUI loop (several times per frame)

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by ardizzle · Nov 11, 2013 at 01:08 PM

Hey man I remember having the same issue a while back. In the end I just made a work around that ended up looking like this

     var firstWait  : boolean = true;
     var secondWait : boolean = false;
     function second_textGUI()
     {
          if(firstWait == true)
          {
               first_text_message = "(Sshhh!!)";
               yield WaitForSeconds(3);
               first_text_message = "(Hmm.. who is he?)";
               firstWait = false;
          }
          if(firstWait == false && secondWait == true)
          {
               yield WaitForSeconds(2);
               first_text_message = "(He might be the murderer!!!)";
               secondWait = false;
          }
          if(secondWait == false)
          {
               yield WaitForSeconds(3);
               first_text_message = "";
               second_en = false;
               //firstWait = true;     undo these comments if you want it to loop
               //secondWait = true;
          }
     }
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 liszto · Nov 11, 2013 at 02:49 PM 1
Share

really ?! and this works better than the other ?!

 IENumerator second_textGUI(){
     first_text_message = "(Sshhh!!)";
     yield return new WaitForSeconds(3);
     first_text_message = "(Hmm.. who is he?)";
     yield return new WaitForSeconds(2);
     first_text_message = "(He might be the murderer!!!)";
     yield return new WaitForSeconds(3);
     first_text_message = "";
     second_en = false;
 }

I can just help you in C# but I think it's weird that your code part won't work.

avatar image
1

Answer by static_cast · Nov 11, 2013 at 03:32 PM

I think the problem here is the fact that it doesn't seem that you are updating the GUIText's text. =0

I would go about that like this:

 var GUITextMessages = GUIText;

 function second_textGUI()
  {
  GUITextMessages.text = "(Sshhh!!)".ToString();
  yield WaitForSeconds(3);
  GUITextMessages.text = "(Hmm.. who is he?)".ToString();
  yield WaitForSeconds(2);
  GUITextMessages.text = "(He might be the murderer!!!)".ToString();
  yield WaitForSeconds(3);
  GUITextMessages.text = "".ToString();
  second_en = false;
  }

It may not work because I don't usually work with GUI stuffs, so be prepared for errors! XD

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

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

21 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

Related Questions

Play AudioClips from a List by using yield WaitForSeconds (C#) 1 Answer

Problem with yield 0 Answers

i need to delay an action but my code isnt working 1 Answer

yield return new WaitForSeconds not working 1 Answer

Buffering button inputs 1 Answer


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