Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Cooper37 · Apr 03, 2014 at 08:04 PM · stringmultipleguitextdialogue

Dialogue & GUI Text String

Hi all! I've been trying to create a simple, easy dialogue system using only one GUIText. So far, this is all I have, but it only displays the last string element typed. Is there a way to have multiple lines, or a line for each element string? Thanks for the help in advance! :D

 var dialogue = false;
 
 var Text : GUIText;
 
 var dialogLines : String; 
 
  
 
 function Start(){
 
 if(dialogue){
 
     for(var item : String in dialogLines){
 
         Text.text = item;
 
     }
 
 }

 
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

Answer by KrisSchnee · Apr 03, 2014 at 09:28 PM

What I'd do is create a list of lines, then cycle through them. In pseudocode:

 lines as (string, 10)
 
 def AddLine(text):
     for i in range(1,9):
         lines[i-1] = lines[i]
     lines[-1] = text

This way you're replacing the contents of lines[0] with the contents of lines[1], which deletes the old lines[0], then moving lines[2] up to 1, and so on, and finally putting the new text into the last slot, #9. If you're then wanting to put all of that text into a single paragraph you could do a string join operation, something like " ".join(lines).

By the way, my limited understanding is that GUIText does not have built-in line wrapping, while the GUI.Box function does (if the GUI style has a checkbox marked for that), so you might want to use GUI.Box instead. I'd like to get a system in place where I can easily say "pop up a box that has this auto-word-wrapped text, then let me know when the user's hit Enter or something to clear it". Please provide a link if you end up producing a good system you'd like to share!

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 Cooper37 · Apr 04, 2014 at 03:42 PM 0
Share

Yeah, GUIText doesn't have text wrapping, so I decided to display one line at a time using indexes. The code seems flawless, if there's such a thing as flawless code, but now it doesn't show anything at all! Any help would be appreciated! :)

 var dialogue = false;
 var Text : GUIText;
 var dialogLines : String[];
 var displayIndex = 0;
   
 private var dialogToggle = true;
 
 function Update(){
     if(dialogue){
         Text.text = dialogLines[displayIndex];
     }
 
     if(dialogue && dialogToggle && Input.Get$$anonymous$$ey("return")){
         NextLine();
     }
 
     if(displayIndex > dialogLines.length){
         audio.PlayOneShot(confirm);
         Node();
         Destroy(gameObject);
     }
 }
 
 function NextLine(){
     displayIndex++;
     dialogToggle = false; 
     yield WaitForSeconds(1);
     dialogToggle = true;
 }
avatar image KrisSchnee · Apr 06, 2014 at 04:56 PM 0
Share

One problem might be "Input.Get$$anonymous$$ey", which should fire every animation frame Enter is held down, rapidly flipping through lines. So I'd change that to Input.Get$$anonymous$$eyDown.

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

21 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

Related Questions

Execute String as Code Line? 1 Answer

How do I find font by passing a string? 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

GuiText Problem 1 Answer

Check if a guiText = a number? 2 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