Hi everyone,
I am building a little dialogue system using the new input system. I have a system of buttons which are populated dynamically with the options (using Ink for this, but it’s not the issue).
I set up my actions by binding the mouse click and space key to the Click action. I have set up the UI event system and I have put on my storyManager object the Player input component set to read the UI section of my event map.
Problem is, everytime I click the button, the onclick event fires twice, causing an exception in the engine.
Here is the code I use to set a listener up in my button:
Choice choice = story.currentChoices[i];
_buttons[i].interactable = true;
_buttonLabels[i].text = choice.text.Trim();
_buttons[i].onClick.AddListener(delegate
{
OnClickChoiceButton(choice);
});
If I debug.log the method OnClickChoicebutton I can see that everytime I click the code runs twice.
void OnClickChoiceButton (Choice choice)
{
//_optionsPresented = false;
Debug.Log(choice.index);
Debug.Log(_optionsPresented);
setUIElement(_dialogueGroup,true);
setUIElement(_optionsGroup, false);
story.ChooseChoiceIndex (choice.index);
RefreshStory();
}
Why it happens? Is it normal? I cannot find a way to have the mouse click work only once.
Help?