Description
The Invoke
method allows you to schedule an action to be executed after a specified delay. This method is useful for timing events or actions that need to occur after a certain period. The action will not be executed if the component is no longer active at the time of invocation.
Usage
To use the Invoke
method, you need to provide three parameters:
secondsDelay
: A float
value representing the delay in seconds before the action is executed.
action
: A System.Action
delegate that defines the method to be executed after the delay.
ct
: A System.Threading.CancellationToken
that can be used to cancel the invocation if needed.
Ensure that the component is active when the action is supposed to be executed, as the action will not run if the component is inactive.
Example
// Example of using the Invoke method in a component
public class MyComponent : Component
{
public void Start()
{
// Schedule an action to be executed after 5 seconds
Invoke(5.0f, () => {
// Action to be executed
DoSomething();
}, CancellationToken.None);
}
private void DoSomething()
{
// Your logic here
}
}