I’m trying to achieve the same functionality as the OnClick() on the Button Script in the UNITY UI. I want to be able to add a GameObject in the inspector, and then select a script that is attached to that object and then select a variable or function from that script.
This picture illustrates what I want:
So far I have been able to add an object to the inspector and add all scripts from that object to an array, my code looks like this:
[CustomEditor(typeof(BarScript))]
public class LevelScriptEditor : Editor
{
//Array that holds all scripts
private MonoBehaviour[] scripts;
public override void OnInspectorGUI()
{
//Creates a reference to the target
BarScript myBarScript = (BarScript)target;
//Set's the barscript's object to the object that we just dragged onto the inspector
myBarScript.ObjectToMonitor = (GameObject)EditorGUILayout.ObjectField(myBarScript.ObjectToMonitor, typeof(GameObject), true);
//Stores all scripts on the object in the MonoBehaviour array
scripts = myBarScript.ObjectToMonitor.GetComponents<MonoBehaviour>();
}
}
This is what the array contains:
My question is. How do I show the names of these scripts in the inspector and expose the members of these scripts, so that they can be selected from the inspector?