Is there a concise way to call the invoke function on a void with parameters, on a delay. I understand that you can call:
Invoke(string function, float delay)
However, that’s not all too helpful when your function has parameter(s)
void writeToConsole(string text){
his is does.
You used to be able to if I remember correctly, but I can’t find it in the docs. So my advice would be to use a Coroutine instead. It works kind of the same way.
StartCoroutine(Foo("Text", 2));
IEnumerator Foo(string text, float delay)
{
yield return new WaitForSeconds(delay);
// code here
}
@ForgeStudios we have created a paid asset that can help you delay functions with parameters in just one line of code with no need to use coroutines.
It’s called Super Invoke, it’s like a more powerful Invoke.
Using Super Invoke your code would become:
float delay = 1f;
SuperInvoke.Run( ()=> writeToConsole("A delayed log"), delay);
You can also create sequences with methods and delays with which you can fully control a complex flow in a handy and easy-to-read way.
For instance you might want to write something to the console and after 1 second you want to instantiate an object. With Super Invoke it will be:
SuperInvoke.CreateSequence()
.AddMethod( ()=> writeToConsole("Hello World"))
.AddDelay(1f)
.AddMethod( ()=> Instantiate(object))
.Run();