call any method
Hi, I would like to replicated something like the event system in my script. I would want the user to specificity what script to use and what function to call in the inspector.
Can this be done without a custom editor?
thanks for all the help,
Answer by Jessespike · Nov 13, 2015 at 08:56 PM
Yea it can be done. Without an Editor script, but you're limiting yourself though, such as you won't be able to have a drop down of functions in the inspector to choose from, similar to how the UI Event system looks. Without using an Editor script, you could simply have a script that contains a public GameObject and a public string. Executing the command would be a SendMessage on the GameObject. It's crude, as this example doesn't send values:
public class MessageSender : MonoBehaviour {
public string FunctionName;
public GameObject Sender;
public void ExecuteCommand()
{
Sender.SendMessage(FunctionName);
}
}
I assume you want to use delegates and Reflection, but I can't see that happening without an Editor script.
Your answer
Follow this Question
Related Questions
How do I get all of my code in start function 1 Answer
Call function when UI text is changed 0 Answers
What go inside the brackets in voids? 1 Answer
Unity Cloud Build call Pre-Export Method with args 1 Answer
Function won't be called 1 Answer