• 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 lechuzacomun1999 · Oct 17, 2021 at 12:00 AM · buttonbugtextsystemdialogue

My dialogue system has a strange bug

Hello, I'm making a point and click game with an RPG-like dialogue system, and the dialogue works well for the most part except for one t$$anonymous$$ng: whenever I go from the dialogue of one object to another, if I change too fast between them, strange characters start appearing and the text is butchered.

Here is an example of what I mean: https://media.giphy.com/media/4QsoxLSInXN0vKciaW/giphy.gif. .The text is in Spanish, but I t$$anonymous$$nk anyone can see where the text isn't behaving like it should (there's a weird amalgamation of symbols and letters at random). The first time I opened both dialogues (the first dialogue is in the drawer object and the second is in the lamp object) they were fine, but the second time, I opened the dialogue in the lamp object too fast and made the text look weird.

The dialogue system for my code is based in the one displayed in the youtube channel Brackeys: https://www.youtube.com/watch?v=_nRzoTzeyxU. I modified t$$anonymous$$s script so it could adapt to my game, but it was mostly so I could trigger the dialogue with UI buttons and to add a Close button (t$$anonymous$$s is why some of the public variables may seem unnecessary but I use them in other UI buttons).

Here is the main code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class DialogueManager : MonoBehaviour
 {
 
     public Text nameText;
     public Text dialogueText;
     public GameObject gameObject;
     public float delay = 0.5f;
     public PlayerController playerController;
     public Toggle myToggle;
     public GameObject endObject;
 
     private Queue<string> sentences;
 
     // Start is called before the first frame update
     void Start()
     {
         sentences = new Queue<string>();
         
     }
 
     public void StartDialogue(Dialogue dialogue){
 
         playerController.enabled = false;
         nameText.text = dialogue.name;
 
         sentences.Clear();
 
         foreach(string sentence in dialogue.sentences){
             sentences.Enqueue(sentence);
         }
 
         DisplayNextSentence();
     }
 
     public void DisplayNextSentence(){
         if(sentences.Count == 0){
             EndDialogue();
             return;
         }
 
         string sentence = sentences.Dequeue();
         StopAllCoroutines();
         StartCoroutine(TypeSentence(sentence));
     }
 
     IEnumerator TypeSentence(string sentence){
         dialogueText.text = "";
         foreach(char letter in sentence.ToCharArray()){
             dialogueText.text += letter;
             yield return new WaitForSeconds(delay);
         }
     }
 
     void EndDialogue(){
         myToggle.isOn = false;
         endObject.SetActive(false);
         playerController.enabled = true;
         gameObject.SetActive(false);
     }
 
 }

It uses a public class that contains a Dialogue named "dialogue":

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 [System.Serializable]
 public class Dialogue
 {
     public string name;
     
     [TextArea(3, 10)]
     public string[] sentences;
 }

It also uses a Trigger function that is called with a button.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class DialogueTrigger : MonoBehaviour
 {
     public Dialogue dialogue;
     public DialogueManager dialogueManager;
 
     public void TriggerDialogue(){
         dialogueManager.StartDialogue(dialogue);
     }
 }
 



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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

Text Appearance Glitch in Unity UI 5.3 3 Answers

Question about raycasting and UI button 0 Answers

Change the text of a UI button on clicking it? 1 Answer

Animated Dialogue Text - Problem With Line Break 2 Answers

All of my textures now appear blurry (2D) 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