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 Ilias · Mar 01, 2011 at 11:00 PM · textcutscenescript-ready-to-useanimated-text

how to make text that is writen automatically, letter by letter

I have a little problem.

How can i make a text that is written by himself. I mean that i have the text, but to make it as an animation like this. ModernCombat2 As you can see in the first seconds, the text is written by himself. how can i do that in my own game?

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

8 Replies

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

Answer by Bunny83 · Mar 02, 2011 at 12:09 AM

Well, that's quite simple. Just store your text in a script variable. A coroutine can copy it char by char.

edit: Added additionalLines variable

It should work... not tested!

 var currentPosition : int = 0;
 var Delay : float = 0.1;  // 10 characters per sec.
 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);
     }
 }
 
 @script RequireComponent(GUIText)

From within this script just use:

WriteText("This is the first line \n this is the second line \n maybe a third?");

To set the text from another script you have to get your script instance first. Note: in this example the script is named "AutoText".

GetComponent.<AutoText>().WriteText("first line \n second line");

To write a new text just call WriteText() with your text as parameter. This script uses a GUIText component.

Comment
Add comment · Show 13 · 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 Ilias · Mar 02, 2011 at 12:18 AM 0
Share

Thnx it works. Thnk you very much

avatar image Ilias · Mar 02, 2011 at 12:23 AM 0
Share

But how can i write the second lline? or should i made a new gameobject?

avatar image Bunny83 · Mar 02, 2011 at 12:33 AM 0
Share

You can make another one or if you assign the text via script add a "newline" character "\n" between the two lines. But that works only if assigned from a script, not in the inspector. I can add a string array so you can assign multiple lines in the inspector. I'll edit my answer. http://forum.unity3d.com/threads/1334-multiple-lines-in-a-GUIText-object

avatar image Bunny83 · Mar 02, 2011 at 12:38 AM 0
Share

Just what ever you want: Open google, type "Unity " and just append what you want to know :D

avatar image Bunny83 · Mar 02, 2011 at 02:05 AM 2
Share

You still don't understand the intention of this site. This site collects "common" questions related to unity. The question you can ask here have to be "of interest to at least one other Unity user somewhere"! Did you even read the FAQs? And even like on every other forum you should search for a similar question before you ask the same question over and over again. This page is like wikipedia. The higher ranked users can edit others questions and answers. As i said there are only a few rules here and they aren't complicated. Sure, everybody needs some time to get into it.

Show more comments
avatar image
20

Answer by lampd1 · Jun 22, 2015 at 07:24 AM

Here's a C# example that works in Unity 5.1.1 using Unity's new UI system:

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class TextTyper : MonoBehaviour {
 
     public float letterPause = 0.2f;
     public AudioClip typeSound1;
     public AudioClip typeSound2;
 
     string message;
     Text textComp;
 
     // Use this for initialization
     void Start () {
         textComp = GetComponent<Text>();
         message = textComp.text;
         textComp.text = "";
         StartCoroutine(TypeText ());
     }
 
     IEnumerator TypeText () {
         foreach (char letter in message.ToCharArray()) {
             textComp.text += letter;
             if (typeSound1 && typeSound2)
                 SoundManager.instance.RandomizeSfx(typeSound1, typeSound2);
                 yield return 0;
             yield return new WaitForSeconds (letterPause);
         }
     }
 }

SoundManager and Loader scripts (based on the examples found in Roguelike tutorial) found here: https://gist.github.com/reidblomquist/c22687bf22238d46447a

Comment
Add comment · Show 7 · 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 kiwiboys · Jan 12, 2016 at 10:48 AM 0
Share

Thanks i really needed this for my next game. well done ;)

avatar image Joogla21 · Feb 25, 2016 at 03:13 AM 0
Share

I can't get this code to work for me...I'm using Unity 5.1.1. I've already created an empty Gameobject and gave it a GUIText component, dragged this code/script as a new component on the empty GameObject. Did I miss something?

avatar image LoungeKatt Joogla21 · Nov 03, 2016 at 07:10 PM 0
Share

This is a revision of the previous answers that adds typing sound effects. You most likely missed the additional scripts from the OP's cough clickbait cough tutorial.

avatar image lampd1 LoungeKatt · Aug 04, 2020 at 11:43 PM 0
Share

Lol, since when is a gist clickbait? Do you even internet? Would you rather me give a link to the official unity3d tutorial those assets are from? https://learn.unity.com/project/2d-roguelike-tutorial

avatar image KodzghlyCZ · Mar 24, 2016 at 06:12 PM 0
Share

Thank ya very much, you will probably be in credits of my game.

avatar image efelatte · Jul 28, 2016 at 11:17 PM 0
Share

Really well written!

avatar image arielsan · Nov 15, 2016 at 06:48 PM 0
Share

@lampd1 How are you handling rich text like colored texts or different fonts? if you write character by character, this is a problem.

avatar image
-1

Answer by AVividLight · Mar 01, 2011 at 11:45 PM

You could buy this. It will open Unity and the the asset store...

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
avatar image
0

Answer by bnmindstorm · Jun 30, 2012 at 06:59 PM

If you want, the extension "TTF Text" that generates text meshes does it directly out of the box, with sound, and for any layout and font. Various other effects are also possible. Check this video : http://youtu.be/RzdjQStYkmU

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
avatar image
0

Answer by LoungeKatt · Aug 25, 2014 at 02:08 AM

 #pragma strict
 public var output : String = "";
 var Delay : float = 0.05;  // 10 characters per sec.
 private var Text : String[];
 public var doubleSpace : boolean = false;
 
 function WriteText(aText : String[]) {
     output = "";
     Text = aText;
 //   TypeText();
    StartCoroutine("TypeText");
 }
 
 function TypeText () {
    for (var word : String in Text) {
       for (var letter in word.ToCharArray()) {
          output += letter;
          yield WaitForSeconds (Delay);
       }
       output += "\n";
       if (doubleSpace)
          output += "\n";
    }
 }

Attach this script to any GameObject that contains GUI elements to be "typed" into. If a button launches the display of text, make sure to place this.GetComponent().WriteText(ARRAY_OF_TEXT); within the button execution. If no button is being used, this line may also be placed in the Start function.

ARRAY_OF_TEXT should be a standard string array separated by line. The text parameter for the GUIText, GUILabel, or GUIButton to have text typed into would then be this.GetComponent().output.

Enabling double space will separate each line by two line breaks.

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
  • 1
  • 2
  • ›

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

14 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

Related Questions

Changing text on Canvas Text is very slow / unresponsive 1 Answer

Scroll intro text 5 Answers

Cutscene(Animation) problem 0 Answers

How to convert a string into a function in JS? 2 Answers

Unity3D Pro - Glowing Effect On Specific item 0 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