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 /
This question was closed Jul 24, 2013 at 09:37 PM by clunk47 for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by AlexanderKFF · Jul 29, 2012 at 10:16 AM · guitextguitext

I have a "display text one letter at a time" script. Can I modify it to display a complete string of text on command?

This is a modified version of AutoType.js, a script from the UnifyCommunity Wiki. The purpose of the script is to display a string of text one letter at a time. It goes onto a GameObject with a GUIText component.

 var currentPosition : int = 0;
 var Delay : float = 0.1;  //Or whatever you want the delay to be
 var Text : String = "";
 var additionalLines : String[];
 
 function WriteText(aText : String) {
     guiText.text = "";
     currentPosition = 0;
     Text = aText;
 }
 
 function Start(){
     for ( var S : String in additionalLines )
         Text += "\n" + S;
     while (true){
         if (currentPosition < Text.Length)
             guiText.text += Text[currentPosition++];
         yield WaitForSeconds (Delay);
     }
 }

I would like to modify this script so that if the user presses any key, the script will stop displaying text one letter at a time, and will just display the whole string of text. So far, I've been unsuccessful in achieving this. Can someone please explain to me how to pull it off?

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 clunk47 · Dec 03, 2012 at 04:22 AM 2
Share

Here ye go. Hit Enter and the text typing coroutine will stop and the entire message will show.

 using UnityEngine;
 using System.Collections;
  
 public class mainText : $$anonymous$$onoBehaviour 
 {
     public float letterPause = 0.05f;
     public AudioClip sound;
      public GUIStyle font;
     string message;
     string text;
  
     void Start () 
     {
         message = "Welcome new warrior! This is a blue screen, you must fight your way out! " +
             "Without any hands or other parts. This may take some time...";
         text = "";
         StartCoroutine(TypeText());
     }
  
     IEnumerator TypeText () 
     {
         foreach (char letter in message.ToCharArray()) 
         {
             text += letter;
             if (sound)
                 audio.PlayOneShot (sound);
                 yield return 0;
             yield return new WaitForSeconds (letterPause);
         }      
     }
     
     void OnGUI()
     {
         GUI.Label(new Rect(0, 0, 256, 1024), text, font);    
     }
     
     void Update()
     {
         if(Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Return))
         {
             StopAllCoroutines();
             text = message;
         }
     }
 }

1 Reply

  • Sort: 
avatar image
3
Best Answer

Answer by Seth-Bergman · Jul 29, 2012 at 10:38 AM

try something like:

    var displayAll = false;
 
     function Update(){
     
     if(Input.GetButtonDown("Fire1")){
     displayAll = true;
 }
     if(displayAll)
     guiText.text = Text;
     }
     
     

you'll want to add a check in the rest:

 function Start(){
 if(displayAll)
 return;
   
     for ( var S : String in additionalLines )
         Text += "\n" + S;
     while (true){
         if (currentPosition < Text.Length)
             guiText.text += Text[currentPosition++];
         yield WaitForSeconds (Delay);
         
     }
 }
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

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

What's wrong with my function? It keeps telling me 'loseText' is not a member of 'UnityEngine.GUIText'. Please help, please and thank you! 0 Answers

Fix Blurry UI text? 10 Answers

Create GUIText from Javascript 3 Answers

Gui text, ammo counter 1 Answer

Trouble getting GUIText positioned correctly. 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