I want to send arguments through the standard Unity listener, as per the tutorial.
mbListener = new UnityAction<string>(SomeFunction);
void SomeFunction(string _message)
{
Debug.Log ("Some Function was called!");
}
Why is this failing with the above error message? BTW I am looking for practical answers and really don't care for tech-talk.
(NB Unity's own manual says it can handle arguments but I cannot work out why this is wrong).
What did you declare mbListener
as? Probably its of type - UnityAction
. Declaring it as UnityAction
and assigning it with UnityAction<string>
is causing you the problem.
Based on your requirement, You can do either of these 2 to fix -
UnityAction<string> mbListener = new UnityAction<string>(SomeFunction);
or
UnityAction mbListener = new UnityAction(SomeFunction);
void SomeFunction()
{
Debug.Log ("Some Function was called!");
}
Edit
As @MotoSV pointed out... you should call it bymbListener("String parameter");
mbListener is a place holder for any function/listner you wanted to call. When you need it to be called you just have to call the UnityAction variable passing the parameter to it. So mbListener("String parameter");
will work for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With