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 /
avatar image
0
Question by Aakash3137 · Mar 22, 2017 at 03:28 AM · textcoroutinestringvirtualreality

Set string.ToCharArray() to the first letter

Hello guys. Here is my current code:

    void Start()
    {
     private IEnumerator coroutine;
     coroutine = TypeText(); 
    }
     IEnumerator TypeText()
     {
         textLeftCopy.text = "";
         textRightCopy.text = "";
         uiTextLeft.text = "";
         uiTextRight.text = "";
 
         foreach (char letter in message.ToCharArray())
         {
             uiTextLeft.text = textLeftCopy.text + letter;
             uiTextRight.text = textRightCopy.text + letter;
             //yield return 0;
             yield return new WaitForSeconds(0.2f);
         }
         
     }
 void updateText()               //UPDATES TEXT VALUE
     {
 
         message = "Hello World";
         StartCoroutine(coroutine);
     }
 void Update()
 {
   if(<condition met>)
    {
        updateText();
     }
    if(<stop writing>)
     {
      StopCoroutine(coroutine);
      }
 }


Basic Info: i'm working on VR and wants my text to be displayed twice at a specific gap. That's why Left and Right texts and im using another two variables to store the message so that my input and output buffers are different , otherwise it was ruining my message itself by writing on the variable from which it was reading also. I want to display a text stored in message in a typing-like method using the TypeText() co-routine. But every time i call this co-routine the text does not reset and starts writing off from where it last left off. I have full control of when to start typing the text and when to make it stop and disappear. Consider my text is : "Hello World" If i stopped the text from writing at "Hell" and when i again wants it to start typing again, it is starting from "Hell" and not from scratch again. I know I must set the message to start again, but i am unable to do that up to this point, failing at each try. So, basically, every time i starts displaying the text, it should start from the first letter of the 'message' variable and not from where it last left off. Any help would be much appreciated. Thanks guys.

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 Aakash3137 · Mar 22, 2017 at 07:21 AM

Okay guys! I got it. I used a For loop instead of a foreach loop and used some global variables to get the state of the current status of text.

 IEnumerator TypeText()
     {
             
         textLeftCopy.text = "";
         textRightCopy.text = "";
         uiTextLeft.text = "";
         uiTextRight.text = "";
 
         arr = message.ToCharArray();
   
         for (i = 0; i < arr.Length; i++)
         {
             if (textWait == 1)
             {
                 yield return new WaitForSeconds(2f);   
                 textWait = 0;
             }
             char letter = arr[i];
             uiTextLeft.text = textLeftCopy.text + letter;
             uiTextRight.text = textRightCopy.text + letter;
             yield return new WaitForSeconds(letterPause);
         }
 
 
     }

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Unity UI: Text Adventure 2 Answers

Unity Native VR doesn't work!! 0 Answers

How do I use two spheres to occlude models in VR environment? 0 Answers

"Namespace Error" when there shouldn't be -1 Answers

Can't return a string after value is true in coroutine 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