0

I'm making a min text adventure and want to have some text displayed for a few seconds before moving on with the program. I found stuff like await etc but can't seem te implement them in my code.

Here's my code:

void state_pad_1 (){
    text.text = "You put the " + weight + "kg on pad 1.\n\n ";
    if (weight ==weight1){      
        myState = States.room_2;}
    else {
    myState = States.room_1;    
    }   
}

So the delay should be between the text and the if statement.

Rand Random
  • 7,300
  • 10
  • 40
  • 88
Alec
  • 11
  • 2
  • Don't know if it will work in Unity but an easy wait in C# is `System.Threading.Thread.Sleep(1000)`. The 1000 is milliseconds – Dumisani Dec 11 '17 at 14:45

1 Answers1

0

What you want is easily done with Coroutines For example you should convert your method into something like this:

IEnumerator state_pad_1 ()
{
  text.text = "You put the " + weight + "kg on pad 1.\n\n ";
  //enter number of seconds you want instead of 5
  yield return new WaitForSeconds(5); 
  if (weight ==weight1){      
      myState = States.room_2;}
  else {
  myState = States.room_1;    
  }   
}

But keep in mind that coroutines are called in a different way, for example:

StartCoroutine("WaitAndPrint");

If you try to use System.Threading.Thread.Sleep(1000) it will kinda freeze your app, so coroutines are better solution.

vmchar
  • 1,314
  • 11
  • 15