Is there a way to invoke a specific number of time?
Hi there!
To have invoke happen a number of times, you could simply put your invoke inside of a for loop to call that function x amount of times. It would look something like this:
void Start () {
// "Invokes" the function 5 times with 0 seconds of delay
for (int i = 0; i < 5; i++) {
Invoke("SomeFunction_1", 0.0f);
}
}
private void SomeFunction_1() {
Debug.Log("Hello world! (version 1)");
}
If that doesn’t work for you, you could also use a little counter used for keeping track of how many times the function has been “invoked” and while that counter has not “depleted” its call times, invoke itself again. Here is an example of this:
void Start () {
// Sets the invoke counter to 3 and starts the initial call of the function
invokeCounter_SomeFunction_2 = 3;
Invoke("SomeFunction_2", 0.0f);
}
private int invokeCounter_SomeFunction_2 = 0;
private void SomeFunction_2() {
if (invokeCounter_SomeFunction_2 <= 0)
return;
Debug.Log("Hello world! (version 2)");
invokeCounter_SomeFunction_2--;
Invoke("SomeFunction_2", 0.0f);
}
Without more details, this is about the best I’ve got. Let me know if this helps!