Skip to content

Instantly share code, notes, and snippets.

@made-indrayana
Last active February 11, 2022 12:46
Show Gist options
  • Save made-indrayana/1145f74b963ab8bede3250548e68a19a to your computer and use it in GitHub Desktop.
Save made-indrayana/1145f74b963ab8bede3250548e68a19a to your computer and use it in GitHub Desktop.
Executing UnityEvent with a predefined delay.
// ExecuteWithDelay.cs
// Author: Made Indrayana
// MIT License
// Delaying an execution of a UnityEvent with a variable wait time.
using System.Collections;
using UnityEngine;
using UnityEngine.Events;
public class ExecuteWithDelay : MonoBehaviour
{
public float waitTime = 1f;
public UnityEvent onFinishedWaiting = new UnityEvent();
public void ExecuteDelayed()
{
StartCoroutine(Execute());
}
private IEnumerator Execute()
{
yield return new WaitForSecondsRealtime(waitTime);
onFinishedWaiting?.Invoke();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment