3DTD/Assets/Scripts/UI/PlayerHealth.cs

32 lines
715 B
C#

using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerHealth : MonoBehaviour
{
public GameObject gameOver;
public TMP_Text text;
void Update()
{
text.text = $"{GameManager.Instance.health} / {GameManager.Instance.startHealth}";
if (GameManager.Instance.health <= 0)
{
StartCoroutine(GameOver());
}
}
private IEnumerator GameOver()
{
gameOver.SetActive(true);
yield return new WaitForSecondsRealtime(5f);
GameManager.Instance.Reset();
SceneManager.LoadScene(0);
}
}