Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Saxgu · Dec 10, 2017 at 08:52 PM · textboxmanager

Am I comparing strings the right way? (I am making a text box for interaction)

Hi guys. I'll try to be as specific as I can. I have the following text on a .txt:

     This is a tree.
     
     This is a tree.
     
     This is STILL a tree.
     
     ...
     
     Really?
     
     THIS IS A TREE FOR THE LAS TIME!

I break the File into lines by using

 textLines = (textFile.text.Split ('\n'));

And I start navigating the textlines array. By using enter I advance to the next line, if it has text it writes it down on the Text Box, if it doesn't it should disbale the text box and the manager. The code for that is this.

 // Update is called once per frame
     void Update () {
 
         //If we haven't passed the last line set current line to the actual line we are on
         //And if we can write whe call the Writing Coroutine, but not before setting canWrite to false
         //So that it cannot be accesed until it is done writing the current line
         if (currentLine <= lastLine) {
 
             currentTextLine = textLines [currentLine];
 
             if (currentTextLine == "") {
                 print ("Empty Line");
                 TurnOFF ();
             }
             if (canWrite == true) {
                 canWrite = false;
                 StartCoroutine ("WriteText");
             }
             //If enter is pressed and the testbox is already initializaed
             //We completly write the current line instantly if it hasn't finished
             //If it has finished it advances to the next line
             if (Input.GetKeyDown (KeyCode.Return) && initialized == true) {
 
                 NextLine ();
             }
             //currentText.text = textLines [currentLine];
         } else{
 
             TurnOFF ();
         }
     }

However if (currentTextLine == "") is never entered, Whenver I get to an empty line the text box and manager stay ON, it writes nothing but they stay ON. The only time it is entered is when I reach the last line which is an empty one. Why does it enters it when it is the last one but not on the others?

My TurnOFF function is.

 void TurnOFF()
 {
     StopCoroutine ("WriteText");
     textBox.SetActive (false);
     this.gameObject.SetActive (false);
 }
Comment
Add comment · Show 1
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 Hellium · Dec 10, 2017 at 09:06 PM 0
Share

Why don't you simply output currentTextLine with a simple Debug.Log? Try this ins$$anonymous$$d :

 if ( string.IsNullOrWhiteSpace(currentTextLine) )

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Minuks · Dec 10, 2017 at 10:38 PM

The empty lines are actually not empty, they contain a line feed (\n), and possibly a return carriage (\r).
You may want to try if (currentTextLine .Replace("\r", "").Length == 0)

Comment
Add comment · Show 4 · 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 Hellium · Dec 10, 2017 at 10:45 PM 2
Share

Because he splits using textFile.text.Split ('\n') the \n character should not be present in the string (However, \r may be here)

avatar image Minuks Hellium · Dec 10, 2017 at 10:52 PM 0
Share

Good point, I edited my answer based on your comment

avatar image Saxgu Minuks · Dec 11, 2017 at 03:08 AM 0
Share

Thanks, I'm not on my PC right now but I will try it.

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

76 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

Related Questions

Help setting up a game manager 1 Answer

Problem with writing text in a box - typewriter style 1 Answer

How do you display a text box on the GUI after a trigger 1 Answer

How do I change the vertical space between lines in a GUI box? 0 Answers

How do I create a text box to display scrollable text I send it via 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