PlayerStats v2
Animate PlayerStats: Visible, Hidden
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
Last updated