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 nuhash · Jan 05, 2013 at 04:28 PM · animationguitextstring

Problem with makeing text appear on screen

I have added functionality to speak with NPCs and I wanted the text to be animated like the typewriter animation in PowerPoint (The text appears letter by letter). I have been able to do so but sometimes the text dissappears for a frame and then reappears.

The entire class is very long so I have included the relavent function. I achieve the animated effect by creating a substring of the original text which increases in length with time so that more of the text is displayed.

     void DisplaySpeech() {
         
         GUI.BeginGroup(new Rect(Screen.width*0.05f, Screen.height*0.7f, Screen.width*0.9f, Screen.height*0.25f));
         
         GUI.Box(new Rect(0,0,Screen.width*0.9f, Screen.height*0.25f),""); //Draws background for text
         
         GUILayout.Label("Text", titleGuiStyle); //A placeholder title will modify later
         
         string sub = interactions.interactions[interactionSelector].text[textSelector].Substring(0,Mathf.RoundToInt(charSelector));
         //The interactions.interactions[interactionSelector].text[textSelector] variable contains a list of strings which are displayed on after another
         //To achieve an animated effect the string is cut into a substring which starts at the beginning for a set number of characters which increase over time
         //The string is then applied to a Label
         GUILayout.Label(sub);
         
         GUI.EndGroup();
         charSelector += Time.deltaTime*textSpeed; //This variable increases with time and so allows for more the string to be copied to the Substring
         
         if(charSelector >= interactions.interactions[interactionSelector].text[textSelector].Length) { //If the charSelector becomes too large for the string
             charSelector = interactions.interactions[interactionSelector].text[textSelector].Length; //Set charSelector to the size of the string
             GUI.Label(new Rect(0,0,Screen.width*0.9f, Screen.height*0.25f), "Continue", titleGuiStyle); //Tells the player that the text has been displayed
             if(Input.GetButtonDown("Interact")) { //If the player continues
                 textSelector++; //Increasing the textSelector allows for the next string to be displayed
                 charSelector = 1; //Resets the charSelector
             }
             if(textSelector >= interactions.interactions[interactionSelector].text.Count) { //If the textSelector is greater than the number of strings
                 Reset(); //Reset all relevant values to this function
                 currentMode = modes.SETFLAGS; //Sets flags relavent to this interaction
             }
         }        
     }

To help people understand the interactions variable is a ScriptableObject containing data about NPCs.

It also contains possible dialogues, interactions.interactions[interactionSelector].text is a list of strings for a dialogue.

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 Davidovich · Jan 05, 2013 at 10:31 PM 0
Share

Nothing stands out in the code above. The problem could perhaps be in the code that's calling DisplaySpeach

0 Replies

· Add your reply
  • Sort: 

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

9 People are following this question.

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

Related Questions

iOS performance: GUItext? want to use text string, but how to instantiate and edit it runtime? 0 Answers

How do i take a string from a gui and show it in the gameworld c# 1 Answer

IF in a GUI 2 Answers

Detect Text in GUI; Print 1 Answer

format text block in GUI.Box 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