Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

Unity action

//You declare that you have a list of actions:

List<Action> list;
//Do not forget to initialize it:

list = new List<Action>();
//Then, you create an action from the function using a lambda expression:

Action action = () => Func1(1);
//And you add the action to the list:

list.Add(action);

//You can, of course, inline the lambda expression:
list.Add(() => Func1(1));

//Afterwards you can call the actions, for example, in a loop:
foreach (var action in list)
{
    action.Invoke();
}
//Actually, you do not need to use Invoke:
foreach (var action in list)
{
    action();
}
//Ah, yes, that works too:
list[position]();
Source by gamedev.stackexchange.com #
 
PREVIOUS NEXT
Tagged: #Unity #action
ADD COMMENT
Topic
Name
1+6 =