Search Unity

How to make the message appear in a few seconds?

Discussion in '2D' started by NoVate911, Jan 23, 2020.

  1. NoVate911

    NoVate911

    Joined:
    Jan 1, 2020
    Posts:
    13
    Hello!
    Tell me how to make a delay in Unity?
    I want a message to be displayed after some time.
    • Example: A message is displayed, and after five seconds another message is displayed.
    If that I’m at Unity recently, so that can be more detailed.
    Thanks to everyone in advance ...
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Hi,

    You could start a coroutine, which waits for a while and then shows your message.
     
  3. Deleted User

    Deleted User

    Guest

  4. NoVate911

    NoVate911

    Joined:
    Jan 1, 2020
    Posts:
    13
    Hi,

    Can't tell me the code? I’m just in Unity recently, but on the Internet, what I want is not present unfortunately!
     
  5. DevBaro

    DevBaro

    Joined:
    Apr 23, 2019
    Posts:
    13
    From documentation (a little bit simplified)

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class ExampleClass : MonoBehaviour
    6. {
    7.     void Start()
    8.     {
    9.         StartCoroutine(WaitAndPrint(2f));
    10.     }
    11.  
    12.     private IEnumerator WaitAndPrint(float waitTime)
    13.     {
    14.         print("Coroutine started");
    15.         yield return new WaitForSeconds(waitTime);
    16.         print("Coroutine ended: " + Time.time + " seconds");
    17.     }
    18. }