# PlayerStats v2

### Animate PlayerStats:  Visible, Hidden

To create an animated UI Prefab:  PlayerStats, where pressing the tab key  causes the panel to slide-off screen is straight-forward.   The script below shows modifications needed for the PlayerStats.cs script to listen for keypress of tab-key.  Note that this version also uses GameData: onPlayerDataUpdate event

Note:  The [ModifyPlayerData.cs](https://kdoore.gitbook.io/cs2335/overview-branchlogic/playerstats-v2/modifyplayerdata) script can also be added to PlayerStats to create an easy way to modify GameData by configuring Buttons in the Inspector.

See the video for [Configuring Animation](https://kdoore.gitbook.io/cs2335/inventory-system/inventory-scriptableobject/customization-steps/ui-animation) of the InventorySystem to see how to animate a simple UI-Panel's visibilty&#x20;

```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; //Directive add for working with UI elements

public class PlayerStats : MonoBehaviour
{

    [SerializeField]
    Text healthText, scoreText;

    bool isVisible = false; //start hidden
    Animator animator;  // animator component required

    // Start is called before the first frame update
    private void Start()
    {
        UpdateDisplay();
        animator = GetComponent<Animator>();
     }

    // Update is called once per frame to listen for kep-press
    private void Update()
    {
         UpdateDisplay();
        //check for tab-key must be checked in Update
        if(Input.GetKeyDown(KeyCode.Tab))
        {
            isVisible = !isVisible;
            animator.SetBool("isVisible", isVisible);
            Debug.Log("Tab Pressed");
        }
    }

    public void UpdateDisplay()
    {
        scoreText.text = "Score: " + GameData.instanceRef.Score;
        healthText.text = "Health: " + GameData.instanceRef.Health;
    
    }

    
} //end class PlayerStats

```
