public static event Action<string> OnGameOver;
public void TakeDamage(float damage)
{
health -= damage;
if(health < 0)
{
OnGameOver?.Invoke("The game is over");
}
}
// can have multiple paramethers, always return null (if you want that it
// retur something you have to create your own event
public static event Action<string> OnGameOver;
public static event Action<float, bool> OnPlayerHurt;
//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]();