Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Jan 23, 2016 at 01:26 AM by siimo for the following reason:

Other

avatar image
0
Question by siimo · Jan 22, 2016 at 06:53 PM · textdialogue

Text letter-by-letter dialogue overflow

I have a dialogue system where letters in a text box show up one by one. The issue is that since letters are added individually to a string, a word that would originally overflow to the next line stays at the top line until all of its letters are loaded. Check out what I mean:

via GIPHY

As you can see in that gif, the word "message" sits on the top line until enough letters are loaded into the string for it to overflow. Is there any way to prevent this? A way to detect if a word will overflow ahead of time perhaps?

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

  • Sort: 
avatar image
0

Answer by kellerr112 · Jan 22, 2016 at 07:56 PM

Yes. You can do this by lerping the string's length from 0 to n.

Here's some pseudocode:

 string str = "I am being lerped right now"; // the string you want 
 public Text UItext // the text you want to apply the string to 
 void Update()
 {
       UItext.text = str;
 }
 IEnumerator AnimateText(float animationTime = .5f)
 {
     float elapsed = 0;
     string targetString = str;
     string startingString = "";
     while(elapsed < animationTime)
     {
         elapsed += Time.deltaTime;
         float t = elapsed/animationTime;
         str = targetString.Substring(0, Mathf.FloorToInt(targetString.Length * t) ) // take the first n letters.
         yield return new WaitForEndOfFrame();
     }
 }



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 siimo · Jan 22, 2016 at 08:56 PM 0
Share

via GIPHY

Same issue when using Substring. In the gif, notice how words like "right" and "lerped" will start off on one line but end up on the following line after the characters load in.

Follow this Question

Answers Answers and Comments

38 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

Related Questions

Who to connect the Character Dialogue to a click event 0 Answers

Dialogue not displaying next sentence 0 Answers

Calling functions that needs to be on update() 1 Answer

Inserting specific words into descriptions stored in XML 0 Answers

Dialogue Skipping Issues? 0 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