2
\$\begingroup\$

I'm trying to create the same functionality that occurs when you are working with a button in uGui in Unity. I know that I have to create a custom inspector, but i'm not sure where to go from there.

Essentially the functionality allows you to drag and drop a script to it's on click portion in the inspector, and then it gives you a list of functions for that script to select. This may sound a little confusing, so here are a few pictures demonstrating the functionality i'm trying to replicate.

1

2

3

4

As you can see above the functionality allows you to drag in a script, select a function to link, and do this for as many or as little scripts as you want by pressing the + or - buttons on the bottom right.

Thanks for any help in advance!

\$\endgroup\$
2
\$\begingroup\$

You need to use UnityEvents to make use of such functionality. Derive a class from UnityEvent and then then declare a public member:

[System.Serializable]
public class MyEvent : UnityEvent<int> {}

public MyEvent onClick;

This will show up as the custom inspector widget you want. To send the event you do something like this:

onClick.Invoke(1);

Take look at this tutorial I made on a Rating Bar widget that uses Unity Events

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .