Configure UI-Button Listeners
Last updated
Last updated
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.
See Unity Button Script API - the Scripting API also shows how to AddListener methods that have input parameters.
In these examples, we'll configure a prefab: ChoicePanel with UI-Panel and 2 child buttons, where each button has the 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 )
modify health using gameData public method takeDamage( int val)
ChoiceButton configured to close it's parent ChoicePanel and to open OptionPanel when clicked