- Home /
Make method variable show up in Inspector
Hey, so I'm trying to achieve what you see below...
See the "OnClick"?
I kind of want to make a method/void variable show up in inspector and then use it. Thanks
Which variable do you want to show up in the Inspector? Is the variable in a script?
Not a variable, a method. I want to make a method field. Where i can drag in a GameObject, see it's attached components/scripts and call methods from them. Just like you do with UI buttons.
I think what you see on the picture is an enum and the method is chosen by a switch (not sure though). For the method to show up I imagine you would need custom editor setup. You can use Action to store methods.
Right but I cant do
public Action method;
//or
public Action[] method;
I'm not sure what you mean. I found a discussion about this: http://forum.unity3d.com/threads/reflection-method-selection-with-an-editor-script.142405/
Answer by kevinrocks_786 · Dec 27, 2015 at 08:36 AM
So I answer my own question... It turns out you have to include the namespace:
using UnityEngine.Events;
And then to have it appear in the editor, you do
public UnityEvent methods;
Then to activate them, you do
methods.Invoke();
Even though I found my own answer, thanks @JedBeryll for your time.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Methods list in inspector 0 Answers
Create a seed or string to run multiple methods. C# 3 Answers
Calling a variable based on a variables name? 1 Answer
How to check if a public method is referenced in inspector 3 Answers