Kinda Code
Home/C Sharp/Unity – How to Run a Function after a Delay

Unity – How to Run a Function after a Delay

Last updated: September 23, 2021

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!