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 LEGEND383 · Jan 01, 2014 at 02:00 PM · guitextnewline

Cannot get newline to show in guitext from script

I am trying to insert a newline into a guitext from a script, but it doesn't show up.

I have tried adding \n, System.Enviroment.NewLine and a string containing a literal newline but none show in the guitext.

The strange thing is when I output the contents of the guitext to a log file and open it, the newlines are there.

Anyone have any idea what the problem could be?

EDIT:

The demo can be found here.

And here's the code I'm using, with the end goal of text wrapping the text to the size of the background, and then outputting it character by character. Also, just isolated the problem to the second part that outputs the text character by character.

 IEnumerator TypeWriter()
 {
     string[] words = currentNode.text.Split(' ');
     for (int w = 0; w < words.Length; w++)
     {
         if (w > 0)
             guitext.text += " ";
         guitext.text += words[w];
         if (guitext.GetScreenRect().width >= guitexture.GetScreenRect().width * .8f)
         {
             guitext.text.Remove(guitext.text.Length - words[w].Length + 1);
             guitext.text += newline + words[w];
         }
     }

     guitext.text = "";
     for (int i = 0; i < currentNode.text.Length; i++)
     {
         guitext.text += currentNode.text[i];

         yield return new WaitForSeconds(typewriterInterval);
     }
 }
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 HappyMoo · Jan 01, 2014 at 03:53 PM

If you set a variable from code, it's \n, if you set it in the inspector, you can try a [Multiline] Attribute, to get a multiline text field.

Are you sure your GUIText is big enough to show both lines?

Comment
Add comment · Show 9 · 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 LEGEND383 · Jan 01, 2014 at 04:31 PM 0
Share

Thanks for the reply. I have tried adding the [$$anonymous$$ultiline] attribute but still get the same result.

avatar image HappyMoo · Jan 01, 2014 at 04:55 PM 0
Share

Ok... let me get you through a simple test:

  • In the hierarchy: Create Guitext

  • Add new Script Component:


    using UnityEngine; using System.Collections;

    public class GUITest : $$anonymous$$onoBehaviour { void Start () { guiText.text = "1\n2"; } }

Start the game and you see the guitext having two lines.

avatar image LEGEND383 · Jan 02, 2014 at 01:33 PM 0
Share

Ok, so the test works. Still can't get it to show using the same guitext as the test with my original script, have edited to put the code and a link to a demo. Thanks for the help so far :)

avatar image GrKl · Jan 02, 2014 at 02:19 PM 0
Share

Hello,

I do not have a good solution, but I tried the same thing two days ago and had the same issue. I do not understand why, but when adding "\n" in a "for" or "foreach" function, it does not work. Though adding it manually (as Happy$$anonymous$$oo proposed) does work. $$anonymous$$y (horrible) solution was thus to add all manually like this:

 guitext.text[1] + "\n" + guitext.text[2] + "\n" + guitext.text[3] + "\n" + guitext.text[4] + "\n" + ...

This might give you a hint to solve your problem

avatar image LEGEND383 · Jan 02, 2014 at 05:04 PM 0
Share

@Gr$$anonymous$$l Thanks, but as this code will be used to show text of any length it would be impractical to do it as in your example.

Show more comments

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

20 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

Related Questions

GUIText new line through inspector 1 Answer

Pairing and GUITexture with a Timer? 1 Answer

Pause not working correctly 1 Answer

[JS] How to display an Int variable through a GUI Text?? [Resolved] 2 Answers

How do I reference a UI text in Unity 5? (JS) 2 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