Call Method After Delay in Unity – Unity By Example

Call Method After Delay in Unity

Steps

  • Create script Delay.cs
using UnityEngine;

public class Delay : MonoBehaviour
{
    [SerializeField] private int _delay;

    private void Start()
    {
        Debug.Log("Start");
        Invoke(nameof(SayHello), _delay); // Invokes the method 'methodName' in 'time' seconds.
    }

    private void SayHello()
    {
        Debug.Log("Hello!");
    }
}
  • Create empty object.
  • Add script to object
  • Press Play and check debug console.

Result

Download

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments