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
0
Question by MrPotatobadger · May 13, 2016 at 01:39 PM · uitextguitextdialoguestrings

Check current letter in typewriter textbox?

Hiya! I'm making an old fashioned RPG dialogue text box for practice. The typewriter type thing, you know what I'm talking about. It works fine, but there's a problem...

I'm unsure of how to check (or if there even is a way to check) what letter is currently being typed. I need this for the sake of ease and versatility. For example, I could make the text display slower after a comma so that there's a pause, or play a specific sound when certain letters appear. The main reason I want this is so I can play a sound effect whenever normal letters are being typed, but to mute the sound when the punctuation like spaces, commas, and periods, come along. Know what I mean?

Here's the all the code I have so far, it's really simple. I wrote detailed comments for ease of reading.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class dialogueWriter : MonoBehaviour {
 
     public float displayRate = 0.7f;
     public float currentTextPos;
 
     public string displayText;
     [TextArea(5, 10)]
     public string fullString;
 
     public string charTalking = "TestNPC";
 
     public int soundEffect;
     public int expression;
 
     // Use this for initialization
     void Start () 
     {
 
     }
 
     void FixedUpdate()
     {
         if (displayText.Length < fullString.Length) //If the length of the displayed text hasn't reached the length of the full string, advance the displayed text by 1 letter.
         {
             DisplayText(); //Run the function that types out the next letter.
             currentTextPos += displayRate; //Add to the counter that advances the text forward by displayRate number of times (0.7)
         }
     }
 
     //Display Text
     void DisplayText() //Type out the next letter
     {
 
             displayText = fullString.Substring(0, (int)Mathf.Floor(currentTextPos)); //Set the displayed text to the full-string up until the current text position value.
             this.GetComponent<Text>().text = displayText; //I forget what this does but it makes it work.
     }
 }
 

Any help would be greatly appreciated. Thanks in advance!

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 v01pe_ · May 15, 2016 at 09:29 PM 0
Share

If displayText = fullString.Substring(0, (int)$$anonymous$$athf.Floor(currentTextPos)); shows what is already "typed" then this would extract the last letter from displayText: displayText.Substring(displayText.Length-1). Is that what you need?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How can I create an NPC Dialogue with UI Text? 1 Answer

String.Remove not working 1 Answer

Predict Text Width of String 0 Answers

Creating High score using GUIText, '>' operation no working 1 Answer

Simple text GUI 2 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