Button.onClick running too many times
Hey guys, I'm trying to make it so that when I press a button, I can add score if its correct. (Think a simple multiple choice question)
I have 3 buttons set up, as well as different states for each question. My issue is that when I press any of the buttons using .onClick, it calculates the code multiple times. like 90+, meaning if I add score of +10, it actually adds 900. The amount of times it triggers is inconsistent as well, upwards of 300 sometimes.
I'm pretty new to button scripting, and I'm working from some code that was passed on to me, so if there is a specific topic I should look into more please do let me know!
The code I currently have is....
void Update()
{
switch(currentState)
{
case States.S1:
//Buttons Code
answerOneButton.onClick.AddListener(delegate ()
{
Debug.Log("this is button");
});
//answerTwoButton.onClick
//answerThreeButton.onClick
break;
}
}
When I click answerOneButton I get the debug "this is button" multiple times. If I can learn how to only trigger that loop ONCE per click, I'm back in business!
Thanks for the advice in advance guys!
Your answer
Follow this Question
Related Questions
Can't access functions on my UI button 1 Answer
How do I control my car with UI buttons? 0 Answers
How can I generate and setup buttons via code 1 Answer
UI Button OnClick Only Works the First Time 2 Answers
UI Button click event through script 1 Answer