Skip to content

Instantly share code, notes, and snippets.

@andydbc
Created November 5, 2024 23:29
Show Gist options
  • Save andydbc/4c0edac9f08beca9791e513138d07558 to your computer and use it in GitHub Desktop.
Save andydbc/4c0edac9f08beca9791e513138d07558 to your computer and use it in GitHub Desktop.
Extension methods to execute an action after a specified delay.
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using System;
using System.Collections;
using System.Collections.Generic;
public static class MonoBehaviourExtensions
{
public static Coroutine DelayedAction(this MonoBehaviour m, float delay, System.Action action)
{
return m.StartCoroutine(DelayedActionCoroutine(delay, action));
}
public static IEnumerator DelayedActionCoroutine(float delay, System.Action action)
{
yield return new WaitForSeconds(delay);
action.Invoke();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment