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
0
Question by SmokeMoneky · Feb 07, 2017 at 04:37 PM · 2dtextcoroutineguitext

Issues with Scrolling Dialogue (repeating characters when printing text)

Hello, I have been following this tutorial, in an attempt to get a basic dialogue box system working for my game. While I have it working just fine, in some cases when attempting to access the dialogue box this will occur:alt text

This problem will only present itself on the first line of the text file, and when left alone for a small amount of time will eventually fix itself, but the same letter doubling will occur when attempting to initiate the conversation.

These are the scripts that manage the dialogue action: public class TextboxManager : MonoBehaviour {

     public GameObject textbox;
 
     public Text theText;
 
     public TextAsset textFile;
     public string[] textLines;
 
     public int currentLine, endLine;
 
     PlayerMovement playermovement;
 
     public bool active,freezePlayer,buttonPress;
     bool waitforpress;
 
 
     private bool isTyping = false;
     private bool cancelTyping = false;
     public float typeSpeed;
 
 
     // Use this for initialization
     void Start () {
         playermovement = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerMovement>();
 
 
 
         if (textFile != null)
         {
             textLines = (theText.text.Split('\n'));
         }
 
         if(endLine == 0)
         {
             endLine = textLines.Length - 1;
         }
 
         if (active)
         {
             EnableText();
         }
         else
         {
             DisableText();
         }
 
     }
 
     // Update is called once per frame
     void Update ()
     {
         if (!active)
         {
             return;
         }
         //theText.text = textLines[currentLine];
 
         if (Input.GetKeyDown(KeyCode.E))
         {
 
             if (!isTyping) {
 
                 currentLine += 1;
 
                 if (currentLine > endLine) {
 
                     DisableText ();
                 } 
                 else {
 
                     StartCoroutine (TextScroll (textLines[currentLine]));
                 }
             } 
 
             //else if scrolling, and isnt already cancelled, cancel typing.
             else if(isTyping && !cancelTyping){
 
                 cancelTyping = true;
 
             }
         }
     }
 
 
     private IEnumerator TextScroll (string lineOfText) {
 
         int letter = 0;
         theText.text = "";
         isTyping = true;
         cancelTyping = false;
 
         while (isTyping && !cancelTyping && (letter < lineOfText.Length - 1)) {
 
             theText.text += lineOfText [letter];
             letter += 1;
             Debug.Log(theText.text);
             yield return new WaitForSeconds (typeSpeed);
             Debug.Log(theText.text);
         }
 
         //if cancelled:
 
         theText.text = lineOfText;
         isTyping = false;
         cancelTyping = false;
         
 
     }
 
     public void EnableText()
     {
 
         GenericInteraction.engaged = true;
         textbox.SetActive(true);
 
 
         active = true;
         if (freezePlayer)
         {
             playermovement.canMove = false;
         }
 
         StartCoroutine (TextScroll (textLines[currentLine]));
     }
 
     public void DisableText()
     {
         GenericInteraction.engaged = false;
         textbox.SetActive(false);
         active = false;
         playermovement.canMove = true;
     }
 
     public void ReloadScript(TextAsset theText)
     {
         if(theText != null)
         {
             textLines = new string[1];
             textLines = (theText.text.Split('\n'));
         }
     }
 }


And the following Script is what activates particular text files attached to different characters

 public class ActivateTextAtLine : MonoBehaviour{
 
     public void ActivateCurrentFile(TextAsset theText,int startLine,int endLine,bool freeze,TextboxManager textBox)
     {
         textBox.ReloadScript(theText);
         textBox.currentLine = startLine;
         textBox.endLine = endLine;
         textBox.freezePlayer = freeze;
         textBox.EnableText();
     }
 }

I can see that the letters seem to be doubling up when printing which would make me think that some how the TextScroll coroutine is being run twice when being activated double printing each pair of letters before eventually writing itself, how this would be solved is beyond me currently so any input would be most appreciated.

dialoge.png (96.1 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

132 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Making texts look smooth good and not pixel crisp no matter their size with TMP & custom fonts 0 Answers

Display rigidbody speed to a world space canvas text 2 Answers

Gui Text won't turn off 0 Answers

Label and line renderer not showing 0 Answers

Mobile game lags when text mesh and gui text updating 0 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