> 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/playerstats-v2/modifyplayerdata.md).

# ModifyPlayerData

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.

![](/files/-MM7YMXG9wv2bXmsQaQr)

![](/files/-MM7Ye4E_BsvBwupA_al)

![](/files/-MM7Z1rI5Y-IZl2J0QGF)

```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

//Add to ChoicePanel or an empty gameObject 
//to allow easy modificationof Score, Health 
//configure to be executed for a Button onClick event in inspector
public class ModifyPlayerData : MonoBehaviour
{
    [SerializeField]
    Text updateText;
    string displayText;
    string newLine = System.Environment.NewLine;  //add newline

    private void Start()
    {
        // GameData.instanceRef.onPlayerDataUpdate.AddListener(UpdateDisplay);
        displayText = "";
        UpdateDisplay();
    }

    public void IncreaseScore(int value)
    {
        GameData.instanceRef.Add(value);
        displayText = "Increase" + newLine + "Score: " + value  ;
        UpdateDisplay();
    }

    public void DecreaseScore(int value)
    {
        GameData.instanceRef.Buy(value);
        displayText = "Decrease" + newLine + "Score: " + value  ;
        UpdateDisplay();
    }

    public void IncreaseHealth(int value)
    {
        GameData.instanceRef.BoostHealth(value);
        displayText = "Boost Health: " + value ;
        UpdateDisplay();
    }

    public void DecreaseHealth(int value)
    {
        GameData.instanceRef.TakeDamage(value);
        displayText = "Decrease" + newLine + "Health: "  + value ;
        UpdateDisplay();
    }

    public void UpdateDisplay()
    {
        if (updateText != null)
        {
            updateText.text = displayText;
        }

    }   

}
```
