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 Anymeese · Feb 09, 2014 at 04:13 AM · waitforsecondsienumerator3dtextstartcoroutine

How to make a 3d text writeOut method?

So I'd like to write a method to make text write out one character at a time like those old games from back in the day. I wrote a simple function for it, but ran into two problems that I don't know how to fix! Here's the code I wrote:

 IEnumerator writeOut3DText(GameObject threeDText, string msg, float timeBetweenLetters)
 {
     threeDText.GetComponent<TextMesh>().text = "";
         
     for(int i = 0; i < msg.Length; i++)
     {
         threeDText.GetComponent<TextMesh>().text += msg.Substring (i, 1);
         yield return new WaitForSeconds(timeBetweenLetters);
     }
 }

1) Whenever the function ran, the first letter would be added, then every letter after that would be added TWICE, with the second being added almost immediately after the first (i.e. both copies of the same letter added in one loop, not once in each loop). I know from testing that this is not being called by the += nor the Substring call, but I don't know how to fix it.

2) the yield return new WaitForSeconds(float time) function is really sporadic and unpredictable. It was very clear that the time between each letter appearing was NOT the same.

NOTE) I also tried turning the whole function into a normal void function and having an IEnumerator just for the wait method, and starting that coroutine in the normal method's for loop, but that didn't wait at all.

So how do I make my text write out one letter at a time, over a consistent amount of time, and without duplicating every letter after the first?

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
Best Answer

Answer by robertbu · Feb 09, 2014 at 04:31 AM

I could not see anything wrong with your code, so I dropped it into a class and tested it. It worked fine. Only one of each letter and the timing was even.

Multiple letters and uneven timing would happen if 1) you launched two coroutines, or 2) you have the same script attached two times.

Take a look at where you call StartCoroutine(). Also use the search box in the upper right of the hierarchy to see if you have multiple instances of the script.

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 Anymeese · Feb 09, 2014 at 05:57 PM 0
Share

$$anonymous$$y problem is that my character model is made up of 2 colliders, not just 1, so it's being called once for each of my player's colliders entering. I completely forgot about that! Tyvm :)

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

18 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

Related Questions

WaitForSeconds does not work 0 Answers

c# waitforsecconds 2 Answers

Fire rate for gun script, c# (not u/s) 1 Answer

Best way to delay the GameOver screen? 0 Answers

Non-invocable member "IEnumerator" cannot be used like a method. Start StartCoroutine from other script ?? 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