I want to make my game so when I talk to a npc the text slowly shows itself and doesn’t just pop up all at once so something like this.
Example:
“hello there”
but instead of show that entire line of text right away I want it to show each letter every second or faster.
something like this…
“h” “he” “hel” “hell” “hello” “hello t” “hello th” “hello the” “hello ther” “hello there”
so each letter shows itself on the screen every second until it spells out the sentance.
2 Answers
2
You’ve tagged this [texture2d] ? Not sure why, as you dont tell how you show the text currently.
But - if I were to make this sort of effect. Called a “type-writer text effect”, I would first create the “source text line” then have a “destination text line” (called buffer or something) where I add 1 char at a time.
Ofcause it all depends on how you show the text-result. But lets say you have a GUI.Box() object and need a string to put into it.
All you need to do is:
- LOOP through all the letters in the SOURCE text.
- grab next letter from the string, which can be done with substring() or similar
- add the letter to the DESTINATION (buffer) text.
- GOTO 1 as long as you havent reach the length.
So its more or less:
for (int cnt=0; cnt < source.Length ; cnt++)
{
string next = source.Substring(cnt,1); // 1 for length of substring to extract)
destination += next; // now add the letter in next at the end of destination string
}
ofcause this loop happens instantly… but thats all there is to it. so if you make a counter that goes up like 10 times pr. second using Update() event and then lets this counter check if its reached MAX or LENGTH … and if not, add a letter more.
Then you ought to be done.
Can you use this advice or is it too pseudo for your skills?
@Eric5h5 - LOL! you are killing me with your simplicity! Great link! :o)
– BerggreenDK