I am working with UnityEvents as stated here. There it is written
When configuring a UnityEvent in the Inspector there are two types of function calls that are supported:
Static. Static calls are preconfigured calls, with preconfigured values that are set in the UI. This means that when the callback is invoked, the target function is invoked with the argument that has been entered into the UI.
Dynamic. Dynamic calls are invoked using an argument that is sent from code, and this is bound to the type of UnityEvent that is being invoked. The UI filters the callbacks and only shows the dynamic calls that are valid for the UnityEvent.
so I get a UnityEvent with an argument as in
public class UnityEventFloat : UnityEvent<float>
{
}
public UnityEventFloat OnUpdateEvent;
This appears in the inspector as
As you can see I have added a callback function setWaitTime
to the UnityEvent.
The function has this shape public void setWaitTime(float t)
After that the UnityEvent is going to be invoked in code as
OnUpdateEvent.Invoke(aValue);
Trying all this, it is not working well since the function when invoked is using as argument 0 (as in the Inspector)
What I want is that it calls the function with the argument aValue
(which is an internal variable in code)
How can I do this? I guess I am not quite understanding the quote above from the documentation. My situation is like the "Static" one, and I require it works like the "Dynamic"
EDIT2:
I got to solve the problem, so I am going to write it in an answer
EDIT:(Old) I tried the proposed answer and I got this I don't know how this can solve the problem (notice that now the parameter is the script. But this is inside the same script (SliderGestureControl))
Actions in Unity Actions are, essentially, ready-made delegates. They can be used to easily create a delegate or delegate event with a void return type. Which means that you can use an action in the same way as you would a delegate, the difference being that you don't need to declare it first.
I finally got to make it work. Apparently I was making a mistake when selecting the function from the drop down list. I selected the function under the "Static" label but I should have selected the same function but under the "Dynamic" label that was at the top of the list (and I didn't see).
With that the function setWaitTime
does not have any parameter in the inspector (so it uses dynamically what is given to it by the UnityEvent.
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