Dynamic commands
If you want even more control over your commands, they can also be added and removed at runtime by accessing the CommandExecutor
class directly.
Adding commands at runtime
Any delegate can be turned into a command using CommandExecutor.AddCommand
. The method simply requires a name for the command, along with a delegate.
private void Start()
{
// The method doesn't return anything, so we'll create an Action.
CommandExecutor.AddCommand("hello", new Action<string>(Hello));
}
private void Hello(string message)
{
Debug.Log(message);
}
Removing commands at runtime
Commands can also be removed at runtime. Even those that were created using the [Command]
attribute. To do so, use CommandExecutor.RemoveCommand
. The example below shows a great way to keep the player engaged for longer.
CommandExecutor.RemoveCommand("quit");
Last updated
Was this helpful?