Last active
February 11, 2022 12:46
-
-
Save made-indrayana/1145f74b963ab8bede3250548e68a19a to your computer and use it in GitHub Desktop.
Executing UnityEvent with a predefined delay.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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