Add a Listener to an UI Button so that it shows in the editor
I want to make an editor script to create a new UI button in a way that when it is created, it already has an On Click() action applied to it in the editor, that should look like this at creation:
What I am trying now is something like so:
GameObject button = new GameObject(buttonLabel);
button.AddComponent<Image>();
RectTransform rt = button.AddComponent<RectTransform>();
//rt..position = Vector3.zero;
Button b = button.AddComponent<Button>();
UnityAction action = new UnityAction(_target.Enter);
action += _target.Exit;
b.onClick.AddListener(action);
But it's not really adding the action at all (or perhaps it does but it is not showing in the editor). It is no matter how I create it, creating something that looks like this:
Is there any way to add an action by script in a way that it appears on the editor just as if I would have added it through the editor without me having to manually do so?
I've looked around a lot but didn't really find a solution. Does anyone know?
Your answer
Follow this Question
Related Questions
Unity 5 - How to duplicate enemies whilst making them unique? 1 Answer
Apply same transform animation to separate objects 0 Answers
How to assign Instantiated object through script? 1 Answer
How do I resolve, get_isActiveAndEnabled can only be called from the main thread error 1 Answer
How to create a script to control a path like in game 'Tbe Witnsss' 0 Answers