How to make the script wait/sleep in a simple way in unity

前端 未结 5 1869
情话喂你
情话喂你 2020-11-22 12:03

How can I put a sleep function between the TextUI.text = ...., to wait 3 seconds between each phrase?

public Text GuessUI;
public Text TextUI;
         


        
5条回答
  •  余生分开走
    2020-11-22 13:00

    You were correct to use WaitForSeconds. But I suspect that you tried using it without coroutines. That's how it should work:

    public void SomeMethod()
    {
        StartCoroutine(SomeCoroutine());
    }
    
    private IEnumerator SomeCoroutine()
    {
        TextUI.text = "Welcome to Number Wizard!";
        yield return new WaitForSeconds (3);
        TextUI.text = ("The highest number you can pick is " + max);
        yield return new WaitForSeconds (3);
        TextUI.text = ("The lowest number you can pick is " + min);
    }
    

提交回复
热议问题