Question by
TheEye2108 · Jun 19, 2017 at 08:16 AM ·
unity 5unity5editor-scriptingeventevent triggering
Need help with adding a function to EventTrigger from editor script
I want to add GameController.LoadLevel(int level) to EventTrigger on click for all the levels i have.
The code should be something like this:
[MenuItem("Midva/Add Function To Event Trigger", false, 12)]
public static void AddFunctionToEventTrigger()
{
GameControllerMenuCombined gameControllerMenuCombined = GameObject.Find("GameController").GetComponent<GameControllerMenuCombined> ();
GameObject[] buttons = GameObject.FindGameObjectsWithTag ("LoadLevelButton");
for(i=0;i<buttons.Lenght;i++)
{
buttons[i].AddComponent<EventTrigger>();
UnityEventTools.AddPersistentListener (buttons[i].GetComponent<EventTrigger>()."onClick", gameControllerMenuCombined.LoadLevel (i));
}
}
Comment
i have this problem as well, does anyone have any answers
Your answer
Follow this Question
Related Questions
How can i add a new item in dropdown options ? 1 Answer
Does Unity pack all files from the project in the build? 2 Answers
Problem exporting solution to WebGL 1 Answer
Unity Ads not showing in editor (dummy ad placement is not showing too) as well as in the build. 2 Answers
Trying find a solution to draw on seams with Ink Painter(Free Real-Time Texture Painting Asset) 0 Answers