Created
August 7, 2021 13:36
-
-
Save kurtdekker/7dd44c4d564fdd6eed2a9032926f442e to your computer and use it in GitHub Desktop.
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
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