Wanted to implement a delay?

I managed to get through the challenge, but wanted to spice up my code a bit by making the game give a slight delay before posting the next line of text, sort of like:

i enter the password
pause 1 second
“mainframe successfully hacked!”
“downloading files…”
pause 1s
“25%”
pause 1s
“50%”
pause 1s
“75%”
pause 1s
“100%!”

What would be the best way of coding this in a way that i can use it in multiple areas rather than with just one instance?

My suggestion would be to implement a coroutine:

    IEnumerator LevelWin()
    {
        yield return new WaitForSeconds(1f);
        Terminal.WriteLine("Mainframe successfully hacked");
        Terminal.WriteLine("downloading files...");
        yield return new WaitForSeconds(1f);
        Terminal.WriteLine("25%");
        yield return new WaitForSeconds(1f);
        Terminal.WriteLine("50%");
        yield return new WaitForSeconds(1f);
        Terminal.WriteLine("75%");
        yield return new WaitForSeconds(1f);
        Terminal.WriteLine("100%!");
    }

You could then call it whenever you want using StartCoroutine(LevelWin())

2 Likes

Privacy & Terms