- Home /
Adding UnityAction to UnityEvent from code
Hello,
I noticed that when adding an action to a UnityEvent from the inspector, you can select a method with 1 or 0 parameters even if the UnityEvent is declared with a strong signature like this
Here OnDie event is taking 2 parameters but I am able to assign a method taking none.
But I am unable to repeat the same behaviour through code as AddListener is only accepting a UnityAction of the same signature lie this
public void Lock(UnityAction<Damager, Damageable> callback)
{
_damageable.OnDie.AddListener(callback);
}
Is it possible to add this same method taking no parameters to the OnDie event through code and how ?
Hope I was clear enough
Thanks
Answer by Hellium · Dec 22, 2018 at 10:21 PM
_damageable.OnDie.AddListener( (damager, damageable) =>
{
Debug.Log( "Do something");
YourFunction( param1, param2, param3, ...);
YourOtherFunction();
});
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Subscribers of Delegates? 2 Answers
How would I go about creating a custom Unity Event in a Custom Unity Editor/Inspector? 0 Answers
[C#] Am I using events right? 2 Answers