- Home /
onClick.AddListener For Button, Spams Console
I have a UI button, and I'm accessing this button from a script not accossiated with it via delegate
placeBetButton.GetComponent<Button>().onClick.AddListener(delegate { test(); });
public void test()
{
count++;
Debug.Log(count);
}
I noticed every time I click the button, the console is spammed with the same debug message exactly 154 times per click. Is there a reason for this? Or did I run into a bug?
I found out why its hitting the console so many time, because I have this script attached to 154 objects. I'll have to find another way to associate a button with this script. I don't what it to affect all of the objects, just a specific one.
Your answer
Follow this Question
Related Questions
Method added on a button click with a delegate is being called twice. 0 Answers
Button Delegate running more than once 1 Answer
Reference For Button Which Calls OnClick 4 Answers
onclick.addlistener only works once 0 Answers
My onclick action listeners I attach to my buttons as I instantiate them only work once 1 Answer