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 /
avatar image
1
Question by PallyTrainer · Dec 27, 2017 at 12:58 PM · textdialogue

How do you make a multiple string dialogue with a typing effect?

Ok I'm terrible at coding, and have spent hours looking for a solution but can't find anything that works. I want to make a simple little cut-scene like an old computer loading where the dialogue comes up with the typewriter effect, stays there for a few seconds, then automatically moves onto the next string with the same effect.

First I tried this, which gave me the typing effect.

     [TextArea(3,5)]
     public string fullText;
     //How long each character will take to appear. 
     public float delay;
     private string currentText = "";
 
     // Use this for initialization
     void Start()
     {
         StartCoroutine(ShowText());
 
     }
 
 
     IEnumerator ShowText()
     {
         //Add a character after delay until it's reached the end of the full text. 
         for (int i = 0; i< fullText.Length; i++) 
         {
             currentText = fullText.Substring(0, i);
             this.GetComponent<Text>().text = currentText;
             yield return new WaitForSeconds(delay);
         }
     }
 }

But since the actual string can't be an array otherwise it just gets error about not having a definition about substring, i'm left with just one page of text to work with. I don't want it to all write out at once, I want there to be a delay between strings. "searching..." [pause] "..." [pause] "No results." sort of thing, with each new string replacing the last. I've tried looking it up but can't find anything that works. Is there anyway to do that with one singular text box?

I tried a different method;

    private Text _textComponent;
 //Array of strings for multiple lines
         public string[] DialogueStrings;
     
         public float SecondsBetweenCharacters = 0.3f;
     //check to see if it's reached end of string 
         private bool _isEndofDialogue = false; 
     
         // Use this for initialization
         void Start () {
             _textComponent = GetComponent<Text>();
 //Start displaying text automatically on start.
             StartCoroutine(DisplayString(DialogueStrings[0]));
     
         }
         // Update is called once per frame
         void Update () {
             
         }
     
         private IEnumerator StartDialogue()
         {
             int dialogueLength = DialogueStrings.Length;
             int currentDialogueIndex = 0;
             
             while(currentDialogueIndex < dialogueLength || _isEndofDialogue)
             {
                 if(_isEndofDialogue == true)
                 {
                     StartCoroutine(DisplayString(DialogueStrings[currentDialogueIndex++]));
                 }
             }
             yield return 0;
         }
     
         private IEnumerator DisplayString(string stringToDisplay)
         {
             int stringLength = stringToDisplay.Length;
             int currentCharacterIndex = 0;
     
             _textComponent.text = "";
     
             while (currentCharacterIndex < stringLength)
             {
                 _textComponent.text += stringToDisplay[currentCharacterIndex];
                 currentCharacterIndex++;
     
                 if (currentCharacterIndex < stringLength)
                 {
                     yield return new WaitForSeconds(SecondsBetweenCharacters);
                 }
                 else
                 {
                     yield return new WaitForSeconds(1f);
                     _isEndofDialogue = true;
                     break;
                 }
                 _textComponent.text = "";
             }
         }
     }

   
 

Which is a poorly altered bit of code originally intended to move to next string after having the player press enter, but copying it word for word didn't work at all, it just made the first string disappear and never show the next.

Sorry this is really lot, I'd appreciate any help a lot.

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 Skoboo · Jul 24, 2019 at 12:49 AM 0
Share

oh my god i can't believe no one has answered this yet. This is so sad I need the answers too Dx

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by goutham12 · Jul 24, 2019 at 07:03 AM

IEnumerator TypeMessage(string msg, Text msgTxt)

 {

     string tempString = "";

     msgTxt.text = tempString;

     int runningIndx = 0;

     while (tempString.Length < msg.Length)

     {

         tempString += msg[runningIndx];

         runningIndx++;

         msgTxt.text = tempString;

         yield return new WaitForSeconds(0.1f);

     }

 }

Hope this helps you

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

125 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 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

Dialogue Skipping Issues? 0 Answers

Best Practice For Storing RPG Dialogue? 1 Answer

How can I update my dialogue text? 0 Answers

Inserting specific words into descriptions stored in XML 0 Answers

How do I change text in timeline animation? 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