How can I sign up for an action method without a variable. I know how to sign a method with a variable, but this option does not suit me.
For example:
public static event Action<float> action_1;
Somewhere in another class:
private void Init(){
AnotherClass.Action_1 += Mehod_1;
AnotherClass.Action_1 += Mehod_2;}
And methods:
private void Mehod_1(float value){}
private void Mehod_2(){}
How can I connect the second method to action?
You can’t. It takes a float. You’ll need to add another action that doesn’t take a float.
Wrap it with an anonymous delegate that takes a float as a forwarding method:
AnotherClass.Action_1 += (f) => Method_2();
Note that if you expect to unregister it, you’ll have to keep a ref to that delegate around:
_someClassLevelFieldToStoreDelRef = (f) => Method_2();
AnotherClass.Action_1 += _someClassLevelFieldToStoreDelRef;
//... later
AnotherClass.Action_1 += _someClassLevelFieldToStoreDelRef;
Though honestly, at this point… why not just make it a class level method rather than a delegate.