1
0
mirror of synced 2024-12-11 05:56:05 +01:00
WACVR/Assets/Script/Essential/CallAfterDelay.cs

26 lines
700 B
C#
Raw Normal View History

// Code from https://forum.unity.com/threads/cant-run-my-coroutine-ondestroy.785756/
// Credit: Kurt-Dekker (https://forum.unity.com/members/kurt-dekker.225647/)
using UnityEngine;
using System.Collections;
public class CallAfterDelay : MonoBehaviour
{
float delay;
System.Action action;
public static CallAfterDelay Create( float delay, System.Action action)
{
CallAfterDelay cad = new GameObject("CallAfterDelay").AddComponent<CallAfterDelay>();
cad.delay = delay;
cad.action = action;
return cad;
}
IEnumerator Start()
{
yield return new WaitForSeconds( delay);
action();
Destroy ( gameObject);
}
}