Unity – How to Run a Function after a Delay

Last updated on September 23, 2021 A Goodman Loading... Post a comment

In order to execute a function after a delay in Unity, you can use Invoke().

If you want to invoke a function after a delay, then repeatedly call it, use InvokeRepeating().

Example:

  void Start()
  {
    Invoke("SayHello", 2.5f); // 

    InvokeRepeating("RepeatMe", 1.5f, 1.0f);
  }

  void SayHello(){
    Debug.Log("Hello!");
  }

  void RepeatMe(){
    Debug.Log(Time.time);
  }

Output:

Happy coding!

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

You May Also Like