- Home /
MethodInfo listing functions and parameters of a public variable
I know how to get methods and parameters. The problem I am having is using a public variable that is set in the editor and getting its methods and variables. Truly what I want is to drag in a script and choose which function to use from that script. All I really need is a an example. I am not asking for a full script or anything just something to guide me on my way to figure it out. Cheers!
Answer by KittenSnipes · Jan 31, 2018 at 10:29 AM
Well to use a public variable in my other public variables I used a Singleton but I still have a problem with my dropdown menu so I will make a new question for that. Thank you for replying @dev-waqas. Cheers and here is a Singleton:
Script:
public class ObjectManager : MonoBehaviour
{
// singleton
private static ObjectManager m_Instance = null;
public static ObjectManager Get()
{
if (m_Instance == null)
m_Instance = (ObjectManager)FindObjectOfType(typeof(ObjectManager));
return m_Instance;
}
// class
public MonoScript ComponentToUse;
}
How to use in other classes:
ObjectManager .Get().ComponentToUse;
I know I needed to use a UnityEvent but thats about as far as I have gotten.
Answer by dev-waqas · Jan 31, 2018 at 06:30 AM
Add a public variable of type unity event in your script like this.
public UnityEngine.Events.UnityEvent callBack;
and whenever you want to invoke function in script simple do.
callBack.Invoke();
What I mean is how would if I had a script and dragged it in to it how would I make it display the methods?
All I need is a simple drop-down menu to show my methods but I have no idea how to show it. Please someone help.