SaveChoice, ChoicePanel
ChoicePanel Prefab:
You will need to create a simple Prefab that you can use in multiple times within one scene and within multiple scenes to allow the player to make choices during gameplay to determine subsequent game conditions.
Update GameData to Version3 to include logic for SaveChoice
The ChoicePanel prefab is quite simple, It's very similar to the OptionPanel prefab, it must be configured as detailed below:
The parent gameObject: ChoicePanel, requires:
Hide_Show_Panel script component
CanvasGroup component - REMEMBER TO ADD CANVAS GROUP
Vertical Layout Group component
Each UI-Button will require an instance of the SaveChoice Script (see below).
SaveChoice.cs
The general idea is that we'd like a simple script that can be attached to any Button so that clicking the Button will update the database for the key,value pair associated with the Button.
Button onClick.AddListener( ) In addition to storing the SaveChoice key,value pair we can also configure these buttons to open panels, trigger dialog, to implement our conditional branching narrative structure. This will be covered in the section: Configure UI-Button Listeners
SaveChoice.cs - Attach to each child Button
Set the Key, Value pair for the SaveChoice Component
The script below is attached to a Button, and has code to be executed when the Button is clicked, so first we have to find the Button Component in Start, this is a bit of a work-around. When one of the Buttons is clicked, it updated the Dictionary in GameData. Then it finds it's parent and gets the CanvasGroup of the parent and hides the entire panel. Then it checks to see if the parent panel has an attached Hide_Show_Panel script with a nextPanelToOpen. It opens that panel and checks to see if there is a ShowChoice script on that Panel, if so, it executes: UpdateDisplay( ). See code for that script below.
KeyValuePair.cs - Data Class created for Dictionary Data
SaveChoice.cs
Last updated