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
1
Question by Story Specialist · May 07, 2010 at 10:49 AM · javascriptguiguitext

Using AutoType script on GUI.Label?

Hey all,

I found this neat little script on the UnifyWiki, which sort of types the text of a GUIText out like a typewriter.

var letterPause = 0.2; private var word;

function Start () { word = guiText.text; guiText.text = ""; TypeText (); }

function TypeText () { for (var letter in word.ToCharArray()) { guiText.text += letter; yield WaitForSeconds (letterPause); }
}

I would very much like to use this functionality in a GUI.Label, and my question is: can I do that?

I'm afraid I don't possess the necessary experience to adequately judge whether this is an actual possibility or just wishful thinking.

-Veliremus

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
4
Best Answer

Answer by Mike 3 · May 07, 2010 at 11:32 AM

Edit: Added code to let you add new words on: careful though, it will go a bit iffy if you call the AddText function too quickly before the other finishes, but i'm sure you can use it as an example to make a better one :)

 var letterPause = 0.2;
 var word = "Test"; // change this one in the inspector
 private var currentWord = "";
 
 function Start ()
 {
     TypeText (word);
 }
 
 function AddText(newText : String)
 {
     word = newText;
     TypeText(word);
 }
 
 private function TypeText (compareWord : String) {
     for (var letter in word.ToCharArray()) {
         if (word != compareWord) break;
         currentWord += letter;
         yield WaitForSeconds (letterPause);
         //for added fun, use this instead :D ...
         //yield WaitForSeconds(letterPause * Random.Range(0.5, 2));
     }  
 
 }
 
 function OnGUI()
 {
      GUI.Label(new Rect(50, 50, 200, 30), currentWord);
 }
          
Comment
Add comment · Show 6 · 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 Story Specialist · May 07, 2010 at 02:19 PM 0
Share

Cool, thanks, that does work. But when I change the text of the label, the "typing" is of course over. So I would have to call the function again. But, when I do that, the old word variable remains.

I have an X$$anonymous$$L reader that feeds new lines into the label dynamically, is there a way for me to detect when this happens and then launch the typing effect again?

avatar image Mike 3 · May 07, 2010 at 03:45 PM 0
Share

edited the answer :)

avatar image Story Specialist · May 09, 2010 at 02:57 PM 0
Share

I can't get it work with my current array system. I'll ask someone I know for help, but thank you, as the system works. Little thing to add, I added a "currentWord = """; in your AddText function, to clear the existing word :).

avatar image HolBol · Aug 28, 2013 at 01:31 PM 0
Share

Cleaned up the formatting here, so it's more readable for other people.

avatar image vijaypandu6 · Jul 16, 2015 at 10:48 AM 0
Share

how can i change font size?

Show more comments

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

3 People are following this question.

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

Create GUIText from Javascript 3 Answers

The next problem with gui. 1 Answer

How do I change the text of a gui image text 1 Answer

GUI Text to GUI Label Script? 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