I’m trying to come up with a dialogue ‘system’ that mimics the type-writer effect with each letter appearing at a time. I just threw this thing together and am lost on how to make this more efficient and easier to use. I’d appreciate any help I can get!
Here’s what I have right now, all to produce a simple “Hello world!”:
void OnGUI ()
{
GUI.Label (new Rect (Screen.width / 2, Screen.height / 2, 500, 500), msg01);
if (Time.time >= currentTime + .05 && msg01 == "H")
{
currentTime = Time.time;
msg01 += "E";
}
else if (Time.time >= currentTime + .05 && msg01 == "HE")
{
currentTime = Time.time;
msg01 += "L";
}
else if (Time.time >= currentTime + .05 && msg01 == "HEL")
{
currentTime = Time.time;
msg01 += "L";
}
else if (Time.time >= currentTime + .05 && msg01 == "HELL")
{
currentTime = Time.time;
msg01 += "O";
}
else if (Time.time >= currentTime + .05 && msg01 == "HELLO")
{
currentTime = Time.time;
msg01 += " ";
}
else if (Time.time >= currentTime + .05 && msg01 == "HELLO ")
{
currentTime = Time.time;
msg01 += "W";
}
else if (Time.time >= currentTime + .05 && msg01 == "HELLO W")
{
currentTime = Time.time;
msg01 += "O";
}
else if (Time.time >= currentTime + .05 && msg01 == "HELLO WO")
{
currentTime = Time.time;
msg01 += "R";
}
else if (Time.time >= currentTime + .05 && msg01 == "HELLO WOR")
{
currentTime = Time.time;
msg01 += "L";
}
else if (Time.time >= currentTime + .05 && msg01 == "HELLO WORL")
{
currentTime = Time.time;
msg01 += "D";
}
else if (Time.time >= currentTime + .05 && msg01 == "HELLO WORLD")
{
msg01 += "!";
}
}