void Invoke( float secondsDelay, System.Action action, CancellationToken ct )

robot_2Generated
code_blocksInput

Description

The Invoke method allows you to schedule an action to be executed after a specified delay in seconds. 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, provide the delay in seconds as a float, the action to be executed as a System.Action, and a CancellationToken to allow for cancellation of the scheduled action if needed.

Ensure that the component is active when the action is scheduled, as the action will not be executed if the component becomes inactive before the delay elapses.

Example

// Example of using the Invoke method
public class MyComponent : Component
{
    public void Start()
    {
        // Schedule an action to be invoked after 5 seconds
        Invoke(5.0f, () => {
            // Action to be executed
            Debug.Log("Action executed after 5 seconds");
        }, CancellationToken.None);
    }
}