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

31 lines
676 B
C#
Raw Normal View History

2024-04-21 07:50:06 +02:00
using System;
2024-04-21 07:33:18 +02:00
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
2024-04-21 07:50:06 +02:00
using UnityEngine.SceneManagement;
2024-04-21 07:33:18 +02:00
public class PlayerHealth : MonoBehaviour
{
2024-04-21 07:50:06 +02:00
public GameObject gameOver;
2024-04-21 07:33:18 +02:00
public TMP_Text text;
void Update()
{
text.text = $"{GameManager.Instance.health} / {GameManager.Instance.startHealth}";
2024-04-21 07:50:06 +02:00
if (GameManager.Instance.health <= 0)
{
StartCoroutine(GameOver());
}
2024-04-21 07:33:18 +02:00
}
2024-04-21 07:50:06 +02:00
private IEnumerator GameOver()
{
gameOver.SetActive(true);
yield return new WaitForSecondsRealtime(5f);
SceneManager.LoadScene(0);
}
2024-04-21 07:33:18 +02:00
}