The following script can be added to PlayerStats ( or any gameObject in a scene) To provide a way to configure a UI Button in the Inspector Panel to modify GameData Score or Health. It's necessary to use a helper script like this since GameData is a singleton and therefore is not available as a gameObject in any scene other than BeginScene, to configure calling public methods to change GameData values.
PlayerStats Prefab: UpdateText:
Note: I have added a new UI-Text field to PlayerStats Prefab to display text to indicate when data's been updated.
usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingUnityEngine.UI;//Add to ChoicePanel or an empty gameObject //to allow easy modificationof Score, Health //configure to be executed for a Button onClick event in inspectorpublicclassModifyPlayerData:MonoBehaviour{ [SerializeField]Text updateText;string displayText;string newLine =System.Environment.NewLine; //add newlineprivatevoidStart() { // GameData.instanceRef.onPlayerDataUpdate.AddListener(UpdateDisplay); displayText ="";UpdateDisplay(); }publicvoidIncreaseScore(int value) {GameData.instanceRef.Add(value); displayText ="Increase"+ newLine +"Score: "+ value ;UpdateDisplay(); }publicvoidDecreaseScore(int value) {GameData.instanceRef.Buy(value); displayText ="Decrease"+ newLine +"Score: "+ value ;UpdateDisplay(); }publicvoidIncreaseHealth(int value) {GameData.instanceRef.BoostHealth(value); displayText ="Boost Health: "+ value ;UpdateDisplay(); }publicvoidDecreaseHealth(int value) {GameData.instanceRef.TakeDamage(value); displayText ="Decrease"+ newLine +"Health: "+ value ;UpdateDisplay(); }publicvoidUpdateDisplay() {if (updateText !=null) {updateText.text= displayText; } } }