How to write and return a call for AddListener
Hello,
I am learning about this stuff now and need some help.
My script I wish to keep as simple as I can, I need to know how to return the proper call, to add a listener object to an instantiated ui button object in the onClick() area.
Here is my code:
// Update is called once per frame
void Update () {
if (!manager) {
Call();
button.onClick.AddListener(Call);
}
}
public GameObject Call() {
if (!manager)
{
manager = GameObject.FindGameObjectWithTag("Manager");
}
return manager;
}
}
I know its really simple and doesn't work, I need to understand how to write the call return type, so I can change my code to work so I can add a listener easily and edit its goodies lol, you know, direct it to its target and the script on the target and direct to what to do with it.
Please help?
Answer by Kastenessen · Jul 18, 2016 at 07:08 AM
Okay, so to get this to work I just changed:
this.button.onClick.AddListener(() => Call());
Tho still does nothing lol. Could anyone help me with working out how to assign something to the onClick when I create a new ui object>?
Nope that's wrong.. What I did was this:
this.button.onClick.AddListener(() => manager.Send$$anonymous$$essage("CreateTitleField"));
So I directed a message to my manager object and activated the function. Works easy, tho not sure how to write the msg so that I can send an argument???
To add a paramater I just did this:
button.onClick.AddListener(() => manager.Send$$anonymous$$essage("CreateTitleField",true));
Easy as.
Your answer
Follow this Question
Related Questions
Add listenner to button in loop error 0 Answers
The count of buttons gives user 0 Answers
Can i update button listener? 0 Answers
Can't Add OnClick.Add.Listener To Multiplayer UI 2 Answers
UI Button OnClick() Will not Trigger Function Call 0 Answers