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 NoSoup4you · Jun 22, 2014 at 12:19 AM · textrpgwraplinebreak

Char-by-char RPG style textbox + word wrapping...

Kinda new here still. Anyway, I've successfully made a textbox method that takes a string, and then draws it one character at a time at x speed with the traditional bloopy sound, etc... The issue is that Unity's built-in word wrap will cause it to draw half the word and then teleport the whole thing to the next line abruptly when it goes over the border.

Currently I'm using a fixed-width font, and I just feed it the character width in pixels, count chars to tell if it's gone over, and then insert \n at the nearest whitespace or hyphen. I'd really like this script to work with any font though, especially variable width fonts... Even with fixed width, there's already a problem where the spaces are narrower than the characters, and I really don't wanna count the width of every individual character.

I've thought about using GUIStyle.CalcSize, but I still need to tell it where in the string to put the linebreaks. Any suggestions?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by sschaem · Jun 23, 2014 at 10:48 PM

One way to do it is always render your entire final text (so wrapping doesn;t change), and you instead insert a color tag after the last character you want to display. ex: If you have a black background, and you text is white, simply add a color tag to make your text black after the last char you want to display.

Video of how its done in "TextMesh Pro" using its built in functionality for reveals. https://www.youtube.com/watch?v=ToTOrYolVuc

alt text

Comment
Add comment · Show 6 · 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 NoSoup4you · Jun 23, 2014 at 11:08 PM 0
Share

Ahaha... Clever hack... I guess it wouldn't work if I had a textured background or something though.

I should look into using Text$$anonymous$$esh Pro. Is it much different from using UnityGUI?

avatar image sschaem · Jun 25, 2014 at 06:36 AM 0
Share

It follows Unity Textmesh closely : here is the online API http://digitalnativestudios.com/textmeshpro/docs/ScriptReference/Text$$anonymous$$eshPro.html

avatar image NoSoup4you · Jun 25, 2014 at 11:20 AM 0
Share

65 dollars, jeez. Isn't there a free way to make characters invisible? Would it be possible to extend UnityGUI and add a hide tag?

avatar image sschaem · Jun 25, 2014 at 09:00 PM 0
Share

http://docs.unity3d.com/$$anonymous$$anual/StyledText.html

Check the color tag and use it as I outlined in my original response.

avatar image NoSoup4you · Jun 26, 2014 at 07:34 AM 0
Share

It just feels wrong making a script that'll only work on solid color backgrounds... That might be the most practical option though...

Show more comments
avatar image
0

Answer by Bunny83 · Jun 22, 2014 at 12:36 AM

Well, this is a very special case which can't be solved that easy i think. You might be able to use GUIStyle.GetCursorStringIndex to detemine the character index where it would wraparound and use that information to insert a newline there.

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

23 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

Related Questions

uGUI Text wrong chinese line break 2 Answers

Predict Text Width of String 0 Answers

Text RPG inventory 1 Answer

Wrapping dynamic text around an object. 1 Answer

How to determine how much of string fits in UI.Text element? 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