> For the complete documentation index, see [llms.txt](https://kdoore.gitbook.io/cs2335/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kdoore.gitbook.io/cs2335/overview-branchlogic/configure-ui-button-listeners.md).

# Configure UI-Button Listeners

In order to create customized branching narratives, it will be necessary to understand how to configure UI-buttons in the Unity Inspector Panel so that when the button's onClick event occurs, then methods will be executed as configured in the Inspector Panel.&#x20;

[See Unity Button Script API](https://docs.unity3d.com/2019.1/Documentation/ScriptReference/UI.Button-onClick.html) - the Scripting API also shows how to AddListener methods that have input parameters.

### UI - Button onClick.AddListeners

In these examples, we'll configure a prefab: **ChoicePanel** with UI-Panel and 2 child buttons, where each button has the [**SaveChoice.cs**](https://kdoore.gitbook.io/cs2335/overview-branchlogic/pages/-MLdn8NcA5ZrNIKGvTn6#savechoice.cs) script attached.  See images below.

Within each scene, multiple instances of the choicePanel prefab can be used to create branching dialog chains, where clicking a choiceButton can do any of the following things depending on how the onClick addListener is configured in the inspector.

* save a key, value pair for the choiceData dictionary
* choose to use or modify a key's value within the choiceData dictionary
* with attached dialogTrigger.cs and conversation scriptableObject, trigger a new dialog
* open OptionPanel giving option to leave the scene, with Hide\_Show\_Panel script.
* modify score using gameData public method Add( int val )&#x20;
* modify health using gameData public method takeDamage( int val)&#x20;

ChoiceButton configured to close it's parent ChoicePanel and to open OptionPanel when clicked

![](https://3353821304-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0-KLgOacVpbicrqehO%2F-MLdnVoG26zk8Y2z0Bf2%2F-MLdq3xDdwpuSHCbM4Ds%2FScreen%20Shot%202020-11-08%20at%203.51.34%20PM.png?alt=media\&token=68e2a4a6-e60a-4be8-bf30-265a9346af03)
