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 Dodomir1 · Jun 06, 2019 at 03:36 PM · textlist

how to make letters appear one by one in a list

i have a dialogue manager in which i can assign the number of lines of text but i can't seem to find out how to make the letters appear one by one because the text is in a list . any ideas how to implement it here is my code.

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;

public class DialogueSystem : MonoBehaviour

{

 public static DialogueSystem Instance { get; set; }
 public GameObject dialoguePanel;
 public string npcName;
 public List<string> dialogueLines = new List<string>();
 Button continueButton;
 Text dialogueText, nameText;
 int dialogueIndex;

   

 private void Awake()
 {
     dialoguePanel.SetActive(false);
     continueButton = dialoguePanel.transform.Find("Continue").GetComponent<Button>();
     dialogueText = dialoguePanel.transform.Find("Text").GetComponent<Text>();
     nameText = dialoguePanel.transform.Find("Name").GetChild(0).GetComponent<Text>();

     continueButton.onClick.AddListener(delegate { ContinueDialogue(); });
     dialoguePanel.SetActive(false);
     if(Instance != null && Instance != this)
     {
         Destroy(gameObject);
     }
     else
     {
         Instance = this;
     }
 }
 public void AddNewDialogue(string[] lines, string npcName)
 {
     dialogueIndex = 0;
     dialogueLines = new List<string>(lines.Length);
     dialogueLines.AddRange(lines);
   
     this.npcName = npcName;
     Debug.Log(dialogueLines.Count);
     CreateDialogue();
 }

  
   


 public void CreateDialogue()
 {
     
     dialogueText.text = dialogueLines[0];
     nameText.text = npcName;
     dialoguePanel.SetActive(true);
 }

 public void ContinueDialogue()
 {
     if(dialogueIndex < dialogueLines.Count-1)
     {
         dialogueIndex++;
         dialogueText.text = dialogueLines[dialogueIndex];
     }
     else
     {
         dialoguePanel.SetActive(false);
     }
 }

}

Comment
Add comment · Show 2
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 Dodomir1 · Jun 06, 2019 at 03:45 PM 0
Share

and my second script for the npc .


 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
  public class NPC : Interactable
 

{ public string[] dialogue; public string npcName;

    public override void Interact();
    {
          DialogueSystem.Instance.AddNewDialogue(dialogue,npcName);
     }
 }
  
avatar image Dodomir1 · Jun 06, 2019 at 03:55 PM 0
Share

and how to add sound to each new line of text

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by phouse2019 · Jun 06, 2019 at 03:57 PM

You are going to want a coroutine for this. When you create your dialogue, it populates a list, yes? You then immedistely read the first line after being created but only proceeded to the following lines on user input, correct?

So once it is created, you want to start a coroutine like this that will take your provided line, whether it is the first, second, or so on, and display each character one at a time.

 {
     Stop coroutine("BuildDialogue");
     StartCoroutine(BuildDialogue(yourLine));
 }
 
 IEnumerator BuildDialogue(string line)
 {
     TextComponent.text = string.Empty;
     For(int a = 0; a < line.length; a++)
     {
         Text component.text += line[a];
         yield return new WaitForEndOfFrame();
     }
 }
 
Comment
Add comment · Show 2 · 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 Dodomir1 · Jun 06, 2019 at 04:06 PM 0
Share
  1. Yes

  2. Yes

  3. i don't understand where to put { stop coroutine ("Buil....."); start coroutine(......); } i make it in update or ?

avatar image Dodomir1 · Jun 06, 2019 at 07:24 PM 0
Share

not working

IEnumerator BuildDialogue(string line) { TextComponent.text = string.Empty; --- underlined (TextCompnent.text) For(int a = 0; a < line.length; a++) ---- underlined everything except 0 { Text component.text += line[a]; ---- underlined (textComponent and line[a] yield return new WaitForEndOfFrame(); } }

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

115 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

Related Questions

A node in a childnode? 1 Answer

Trouble displaying lists of strings in a text box 1 Answer

unity 5 change text on UI scrollRect button c# 0 Answers

Writing data from multiple instances of a script to text 1 Answer

dialogue/text box list not working as intended 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