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 Giljak · Mar 02, 2021 at 01:17 AM · waitforsecondscoroutines

WaitForSeconds is going too fast

Well... I want to have a dialogue system where I can have control over pretty much every sentence. So, I decided to do this script in which I can make new methods to tell each sentence what to do like I could put an animation at the end or start of the dialogue, I can put an effect or something. so I made it so that it takes a display of arrays and then loops through them and activating initialize sentence and then waiting until it ends with the bool result.

  public TMP_Text TextBox;
     public Canvas TextBackground;
     SoftDiologueDisplay Container;
     Queue<string> AllText;
     SoftTextRunner Runner;
     bool result;
 
     private void Awake() {
         AllText = new Queue<string>();
         Container = FindObjectOfType<SoftDiologueDisplay>();
         Runner = FindObjectOfType<SoftTextRunner>();
         
     }
     private void Update() {
         if(result == true)
         {
             result = false;
         }
         print(result);
         print(Container.Sentences.TimeBetweenText);
     }
     
     public void InitializeText(SoftDiologueDisplay Diologue)
     {   
         AllText.Clear();
         TextBackground.gameObject.SetActive(true);
             foreach(string text in Diologue.Sentences.Text)
             {
                 AllText.Enqueue(text);
             }
         StartCoroutine(NextSentence());
     }
     public IEnumerator NextSentence()
     { 
         while(AllText.Count > 0)
         {
             string sentence = AllText.Dequeue();
             TextBox.text = sentence;
             yield return new WaitForSecondsRealtime(Container.Sentences.TimeBetweenText * Time.deltaTime * 100 );
         }
         End();
     }
     void End()
     {
         TextBackground.gameObject.SetActive(false);
         result = true;
     }
     public IEnumerator AddingToSoftDiologueToStart(SoftDiologueDisplay[] SoftRunner)
     {   print(SoftRunner.Length + " hi");
         for(int a = 0 ; a < SoftRunner.Length; a++)
         {      
             InitializeText(SoftRunner[a]);
             yield return new WaitUntil(() => result == true);
             print("Wellllllllll");
         }
     }
     public void startingSentences(SoftDiologueDisplay[] diplay)
     {   
         StartCoroutine(AddingToSoftDiologueToStart(diplay));
     }

so my problem at the moment is that when it finishes up the first cycle... when the first item in the array of softdiologuedisplay in AddingtoSoftdiologuetostart, the rest of them start getting skipped over or go by pretty fast on nextsentence. If someone can help me with this code I'd greatly appreciate it. I'm a noob and I just start writing code as I go so if this is very choppy or it doesn't make sense please give me some criticism and I'll try to fix it. Also if you know a better way of doing a dialogue that has dialogue options, is very customizable, and is over all better than mine... pls tell me :)

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
0

Answer by $$anonymous$$ · Mar 02, 2021 at 01:35 AM

      public IEnumerator NextSentence()
      { 
          while(AllText.Count > 0)
          {
              string sentence = AllText.Dequeue();
              TextBox.text = sentence;
              yield return new WaitForSecondsRealtime(Container.Sentences.TimeBetweenText);
          }
          End();
      }
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 $$anonymous$$ · Mar 02, 2021 at 01:36 AM 0
Share

This should work.

The problem was you were multiplying by Time.deltaTime which is not needed

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

114 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 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 avatar image avatar image

Related Questions

How to gradually increase difficulty. 1 Answer

Using coroutines to do attack patterns 1 Answer

Can specified frames of an audio track trigger events? 0 Answers

Mysteries of yield 1 Answer

How to decrease gravityScale in period of time? 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