Skip to content

Instantly share code, notes, and snippets.

@kurtdekker
Created August 7, 2021 13:36
Show Gist options
  • Save kurtdekker/7dd44c4d564fdd6eed2a9032926f442e to your computer and use it in GitHub Desktop.
Save kurtdekker/7dd44c4d564fdd6eed2a9032926f442e to your computer and use it in GitHub Desktop.
using UnityEngine;
public class CallWhenTrue : MonoBehaviour
{
System.Func<bool> test;
System.Action action;
public static CallWhenTrue Create( System.Func<bool> test, System.Action action)
{
CallWhenTrue cwt = new GameObject("CallWhenTrue").AddComponent<CallWhenTrue>();
cwt.test = test;
cwt.action = action;
return cwt;
}
void Update()
{
if (test())
{
action();
Destroy ( gameObject);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment