Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity action example

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;
Comment

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]();
Comment

PREVIOUS NEXT
Code Example
Csharp :: exception is null c# 
Csharp :: How to create a class and objects in C# 
Csharp :: math.pow in C# using loop 
Csharp :: .net using appsettings variables 
Csharp :: Proxy in Config 
Csharp :: unity unit testing 
Csharp :: c# list initialize 
Csharp :: while loop in c# 
Csharp :: flyt wordpress fra localserver 
Csharp :: how to get the dynamic year for your web app in mvc 
Csharp :: ioptions mock c# unittest 
Csharp :: DataGridView set column cell Combobox 
Csharp :: mock async method c# reutrnd 
Csharp :: how to solo squad in fortnight 
Csharp :: c# odp.net close session 
Csharp :: c# ping all machines on local network 
Csharp :: infinit range loop c# 
Csharp :: wpf mvvm crud example 
Csharp :: #movement speed c 
Csharp :: entity framework dynamic search solution 1 
Csharp :: pyqt send message to another instance 
Csharp :: c# get error message from cmd command 
Csharp :: replace filename extension c# 
Csharp :: how to learn c# fast to learn unity 
Csharp :: C# calling method name 
Csharp :: how to make a c# encrypt and decrypt string cmd 
Csharp :: C# USING SHARED CLASS 
Csharp :: Delegate no parameter no return 
Csharp :: TextBox filling in C# 
Csharp :: IAuthorizationFilter OnAuthorization AuthorizationContext MyAuthorizeAttribute HttpUnauthorizedResult HttpContext 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =