- Home /
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!
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?
Your answer
Follow this Question
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