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 yusolaifdfer · Jan 12, 2013 at 02:51 PM · textguitextwaitforsecondsrpg

AutoType script problem.

I am trying to make a small cutscene with some text shown in the bottom of screen I want the text to appear one word at a time like in RPG games. I tried using the AutoType script, it works fine when I put it on the guitext and put the text in the guitext using inspector. But when I use a script like

 var textString : GUIText;
 function Start {
 textString.guiText.text = "Testing";
 } 

it doesn't work like its supposed to work with the AutoType script. For who don't know about AutoType here is the link and code itself.

 var letterPause = 0.2;
 var sound : AudioClip;
  
 private var word;
  
 function Start () {
     word = guiText.text;
     guiText.text = "";
     TypeText ();
 }
  
 function TypeText () {
     for (var letter in word.ToCharArray()) {
         guiText.text += letter;
         if (sound)
             audio.PlayOneShot (sound);
         yield WaitForSeconds (letterPause);
     }        
 }

http://wiki.unity3d.com/index.php?title=AutoType

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 $$anonymous$$ · Jan 12, 2013 at 05:35 PM 0
Share

did it work for you?

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by $$anonymous$$ · Jan 12, 2013 at 03:19 PM

This is because in the Start() method the script actually runs some logic and it launches the TypeText() coroutine. However when you change the text property manually, you do not trigger the effect, TypeText() isn't called. This is what I advise:

 var letterPause = 0.2;
 var sound : AudioClip;
 
 private var message;
 
 function Start () {
     SetText(guiText.text);
 }
 
 function TypeText () {
     for (var letter in message.ToCharArray()) {
        guiText.text += letter;
        if (sound)
          audio.PlayOneShot (sound);
        yield WaitForSeconds (letterPause);
     }   
 }
 
 function SetText(text : string)
 {
     StopCoroutine("TypeText");
     message = text;
     guiText.text = "";
     StartCoroutine("TypeText");
 }

And from now on, use SetText("message"); to change the text, and it will even stop the current AutoTyping and start it over with the new text.

Comment
Add comment · Show 3 · 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 yusolaifdfer · Jan 12, 2013 at 05:36 PM 0
Share

I am using another script attached to another object to pass the 'string' data to the guittext and I attached this script to the guittext and it gave me errors in line 'function settext(text : string)' here i changed it to String then it gave error in line 12 tochararray not member of object, I changed private var message : String; but now its no error but just same story don't work

avatar image $$anonymous$$ · Jan 12, 2013 at 07:15 PM 0
Share

What do you mean by "don't work"? This works for me, I tested it. If you get a reference to the AutoType component, you can set it from any other script and it automatically does the AutoTyping thing. But you $$anonymous$$UST use SetText(), don't set the guiText.text directly. Can you show me how you're using this from another script? You can use it like this:

someGUITextObject.GetComponent(AutoType).SetText("blabla")

or:

var typer = someGUITextObject.GetComponent(AutoType); typer.SetText("blabla");

avatar image yusolaifdfer · Jan 13, 2013 at 05:13 AM 0
Share

GOT IT! I was doing this //var text = textString.GetComponent(autotype); //text.message = "What is happening";

Thank you. Awesome Answer

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

8 People are following this question.

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

Related Questions

How to make a cutscene like RPG Games 1 Answer

Predict Text Width of String 0 Answers

Text RPG inventory 1 Answer

How to set different alignments to differenent lines of text in one field of text 0 Answers

How to display an array of texts on one at a time on button press? 3 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